[C ++] refresher (iii) loops, and branching

cycle

for loop

for(init; condition; increment)
{
	conditional code;
}

foreach loop

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

while loop

while(condition) 
{
	statement(s);
}

do-while loop

do {
	statement(s);
}while( condition );

Loop control statements

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

Branch

if and else statements

if(boolean_expression) 	
{
} 
else 
{ 
}

switch statement

switch(expression)
{ 
	case constant-expression : 
		statement(s); 
		break; 
	case constant-expression : 
		statement(s);
		break;
		
	default : 
		statement(s); 
}

Please indicate the source, permanently updated links in this article: https://blogs.littlegenius.xin/2019/08/05/【C- refresher] three-cycle branch /

Published 44 original articles · won praise 46 · views 9172

Guess you like

Origin blog.csdn.net/qq_38962621/article/details/98481922