举个例子:
- #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;
来源: http://www.bubuko.com/infodetail-3348794.html