Three types of procedures runtime structures: sequential structure, selection structure, cyclic structure.
Sequential structure : program executed in order to jump does not occur.
Select structure : execute different statements based on conditions.
Loop structure : the determination condition is satisfied, a section of code repeatedly cycle.
First, select the structure
// line format statements if () { } // multi-line format statements if () { } the else { } // multiple conditional statements if () { } the else if () { } the else [ } // nested if statements ( i.e. if statement or else statement can be embedded in multiple-else if) if () { if () { } else { } } else { if () { } else { } }
Ternary operator expression :( 1) (expression 2) expression :( 3), explained:? 1 if the expression is true, then run the expression 2, or 3 runs expression.
The switch statement:
Switch (expression) { Case Results 1: execute statement; BREAK ; Case Results 2: execute statement; BREAK ; . . . Case Results: execute statement; BREAK ; default : execute statement; BREAK ; }
Second, the loop structure
the while (loop condition) { loop; }
do {loop} the while (loop condition);
for ( int I = 0 ; I < 10 ; I ++ ) { execute statement; }
Nested loops: loop which then embedded in another cycle.
Third, the jump statement
break; continue; goto: unconditional jump; (try not to use goto)
#include <iostream> using namespace std; int main() { cout << "1.xxx" << endl; goto flag; cout << "2.xxx" << endl; cout << "3.xxx" << endl; flag: cout << "4.xxx" << endl; system("pause"); return 0; }
Output: