【C++温故知新】(三)循环与分支

循环

for循环

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

foreach循环

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

while循环

while(condition) 
{
	statement(s);
}

do-while循环

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

循环控制语句

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

分支

if和else语句

if(boolean_expression) 	
{
} 
else 
{ 
}

switch语句

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

转载请注明出处,本文永久更新链接:https://blogs.littlegenius.xin/2019/08/05/【C-温故知新】三循环与分支/

发布了44 篇原创文章 · 获赞 46 · 访问量 9172

猜你喜欢

转载自blog.csdn.net/qq_38962621/article/details/98481922