循环语句中的continue与break 1.for语句中

举个例子:

#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;

int main (void){
int i = 0;
string ret;

for(int i = 0;i < 5; i++){
cout<<"开始第"<<i+1<<"次相亲"<<endl;
cout<<"你有钱吗?";
cin>>ret;
if (ret != "yes"){
cout<<"再见"<<endl;
continue;
}
cout<<"加个微信吧"<<endl;

}
system("pause");
return 0;
}

continue :退出本次循环执行下一次循环,在这里的for语句中,如果输入了“no”,返回执行下一个循环,先执行i++,在判断i<5.

break;

猜你喜欢

转载自www.cnblogs.com/Ybossy/p/12094280.html