大家都知道,在 bat 类型程序中,goto 是一种循环。那么,在 c++中,如何使
用 goto 呢?
目录
• 定义
• 使用
•
o 如何跳出循环?
定义
goto 是 c++中的关键字,使程序跳到你的标签位置。
使用
与 bat 不同的是,在 c++里,你必须先定义它。
例:
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
cin>>a>>b;
goto l;
l:
cout<<a+b;
goto l;
return 0;
}
如何跳出循环?
可以定义一个 if 语句。
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
cin>>a>>b;
int m=a+b;
goto l;