循环

for循环

1
2
3
4
for(init; condition; increment)
{
conditional code;
}

foreach循环

1
2
3
4
5
int myArray[5] = {0,1,2,3,4};
for (const int i : myArray)
{
cout << i << endl;
}

while循环

1
2
3
4
while(condition) 
{
statement(s);
}

do-while循环

1
2
3
do {
statement(s);
}while( condition );

循环控制语句

  • break
  • continue
  • goto
    1
    2
    goto label; 
    label: statement;

分支

if和else语句

1
2
3
4
5
6
if(boolean_expression) 	
{
}
else
{
}

switch语句

1
2
3
4
5
6
7
8
9
10
11
12
switch(expression)
{
case constant-expression :
statement(s);
break;
case constant-expression :
statement(s);
break;

default :
statement(s);
}