Using continue in a switch statement

后端 未结 7 513
盖世英雄少女心
盖世英雄少女心 2020-12-13 03:29

I want to jump from the middle of a switch statement, to the loop statement in the following code:

while (something = get_something())
{
    swi         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 03:46

    Yes, continue will be ignored by the switch statement and will go to the condition of the loop to be tested. I'd like to share this extract from The C Programming Language reference by Ritchie:

    The continue statement is related to break, but less often used; it causes the next iteration of the enclosing for, while, or do loop to begin. In the while and do, this means that the test part is executed immediately; in the for, control passes to the increment step.

    The continue statement applies only to loops, not to a switch statement. A continue inside a switch inside a loop causes the next loop iteration.

    I'm not sure about that for C++.

提交回复
热议问题