I think that the C language is still a beginner, and it seems that I have overestimated myself. I didn't expect such an interesting thing in this place. In some cases, I think it is necessary to go deeper to get started ....
========================================================== ==========================================================
Copy codeThe Code is as follows: # include <stdio. h>
Int main (void)
{
Int flag = 0;
For (int j = 0; j <2; j ++ ){
If (j = 0 ){
Switch (j ){
Case 0:
Continue;
}
Flag = 1;
}
}
Printf ("flag: % d \ n", flag );
}
Output:
Flag: 0
If the code is:
Case 0: break;
Output:
Flag: 1
========================================================== ====================================
Let's look at it again:
Copy codeThe Code is as follows: # include <stdio. h>
Void main ()
{
Int flag = 0;
Int j = 0;
For (j = 0; j <2; j ++ ){
If (j = 0 ){
If (j = 0 ){
Continue;
}
Flag = 1;
}
}
Printf ("flag: % d \ n", flag );
}
Output:
Flag: 0
If the code is:
Break;
Output:
Flag: 0
========================================================== =
In the C language, the description of continue and break is as follows:
The break statement can exit from the inmost loop or switch statement.
The continue statement can only appear in the for, while, And do loops.
========================================================== =
Conclusion:Continue is only valid for the loop body that directly contains it (that is, for, while, the loop body in switch {}). break is effective for, while, switch block.
For example, if the break or continue appears in the code that does not contain the switch, the break jumps out of the loop body and the continue jumps out of this loop.
In the code of nested switch statements in a loop, break only jumps out of the innermost block. If this block is a switch, it only jumps out of the switch.
Even if the continue appears in the switch block, because the range of the continue is only for loop statements such as for while, it does not work, it still jumps out of this loop.
If you do not pay attention to it, you will also think that the switch statement block is jumped out.