C++ break语句,continue语句,goto语句
break 语句的作用:
跳出当前循环,中断当前循环
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
cout << i << endl;
if (i==5)
{
break;
}
}
return 0;
}
打印结果:
continue语句的作用:
跳过本次循环, 整体循环继续.
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
if (i==5)
{
continue;
}
cout << i << endl;
}
return 0;
}
打印结果:
goto语句的作用:
改变语句执行的顺序,结束循环.
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
cout << i << endl;
goto label;
}
label:
cout << "11111" << endl;
return 0;
}
打印结果:
还没有评论,来说两句吧...