C Switch-case curly braces after every case

前端 未结 5 1883
感动是毒
感动是毒 2020-12-08 02:07

In a C switch-case flow control, it\'s required to put curly braces { } after a case if variables are being defined in that block.

5条回答
  •  青春惊慌失措
    2020-12-08 02:42

    Just to add a minor point many editors & IDEs allow blocks to be collapsed and/or auto indented and several allow you to jump to the matching brace - I personally don't know of any that allow you to jump from a break to the matching case statement.

    When debugging, or re-factoring, other peoples, (or even your own after a few months), code that contains complex case statements the ability to both collapse sections of the code and to jump to matching cases is invaluable, especially if the code contains indentation variations.

    That said it is almost always good advice to avoid complex case statements like the plague.

提交回复
热议问题