continue语句
作用:在循环语句中,跳过本次循环中余下尚未执行的语句,继续执行下一次循环。
#include<bits/stdc++.h>
using namespace std;
int main() {
for (int i = 0; i < 100; i++)
{
if (i % 2 == 0)//continue是到满足该条件时,不再向下执行,而是执行下一次循环
{
continue;//break是直接跳出循环,不会再进入循环
}
cout << i << endl;
}
system("pause");
return 0;
}
学习过程:这个时候要注意的就是break和continue的区别,break终止了循环,而continue没有终止循环,只是筛选完条件后再执行下次循环。
goto语句
作用:可以无条件跳转语句
语法:goto 标记;
用法:当标记名字存在时,执行到goto语句的时候,会跳转到标记处
#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "1" << endl;
goto FLAG;//因为FLAG存在,输出1后跳转到了下面
cout << "2" << endl;
cout << "3" << endl;
cout << "4" << endl;
FLAG://从标记处继续执行
cout << "5" << endl;
system("pause");
return 0;
}
注意:编程过程中不要经常使用goto语句,容易引起程序流程混乱