Namespaces
Variants

Talk:c/language/switch

From cppreference.com

> The break statement, when encountered anywhere in statement, exits the switch statement...

This code prints "hello world\n", even with break; in the start of switch:

int main(void) {

   switch(1) {
       break;
       case 1:
           puts("hello world");
           break;
   }

}

I think we need to rephrase the statement above like this:

> The break statement, when encountered anywhere in statement _after case_, exits the switch statement...

what it meant to say is that it has to be *encountered*, as in, by the flow of execution, not just exist somewhere. And it could be encountered before the first case label (if there's a goto label earlier). --Cubbi (talk) 09:41, 23 June 2020 (PDT)