for loop if and switch selection structure is changed by differences in break state

 1 #include <cstdio> 
 2 int main(){
 3     for(int i=0;i<5;i++){
 4         if(i==2)    break;
 5         printf("%d\n",i) ;
 6     }
 7     printf("****\n");
 8     for(int i=0;i<5;i++){
 9         switch(i){
10             case 2:break;
11         }
12         printf("%d\n",i) ;
13     }
14 }

Output:

0
1
****
0
1
2
3
4

if condition is nested in a for loop, may be made BREAK, early termination of the cycle;

The switch in the multi-nested for loop branch selection statement, break statement will terminate the current case, but does not terminate the loop early.

Guess you like

Origin www.cnblogs.com/cuphead/p/11494580.html