2. Role
Break
1. Use Cases
1> Switch statement: Exit the entire switch statement
2> loop structure: Exits the entire loop statement
* While
* Do While
* FOR
2. Attention points
Valid only for the nearest loop structure
Continue:
1. Use Cases
Loop structure: End the current cycle body, enter the next cycle body
* While
* Do While
* FOR
2. Attention points
Valid only for the nearest loop structure
2. Code
1#include <stdio.h>2 3 intMain ()4 {5 /*6 for (int i = 0; i<5; i++)7 {8 printf ("%d\n", I);9 Ten if (i%2) One {//I is odd: 1, 3 A continue; - } - }*/ the /* - for (int i = 0; i<5; i++) - { - + printf ("Hahaha \ n"); - + continue; A at printf ("hahaha 23\n"); - }*/ - - for(inti =0; i<3; i++) - { - for(intj =0; j<2; J + +) in { - if(j==1) to { + Break; - } the *printf"a\n"); $ }Panax Notoginseng - Break; the +printf"b\n"); A } the + return 0; -}
3. Summary
I. CHOICE of structure
1.if
1> structure
if (condition) {
} else if (condition 2) {
} else if (condition 3) {
} else {
}
2> Features
* At the same time, only one curly brace code will be executed
2.switch
1> structure
Switch (value)
{
Case value 1:
Break
Case Value 2:
Break
Case Value 3:
Break
Default
Break
}
2> Features
1> by default, only one of the code following the case is executed
2> If there is no break behind a case, and if the case is true, then the statements in all of the following are executed sequentially until a break is encountered
3> if you want to define a new variable after the case, you must enclose it in curly braces {}
Second, the cycle structure
1.while
1> Features: If the initial condition is not established, the loop body will never be executed
2.do while
1> features: At least one cycle body will be executed regardless of whether the condition is established
3.for
4. Select
1> general preference for use for loops
2> and then consider the while.
3> finally consider the Do and
"Learning Notes" "C language" break and continue