c++ goto的使用

c++ goto 语句的使用

1.定义一个类似标签的东西lable

2.使用goto关键字,跳转到lable, goto lable

 1 #include <iostream>
 2 #include <string>
 3 #include <stdlib.h>
 4 #include <stdio.h>
 5 
 6 
 7 #include "header3.h"
 8 
 9 using namespace std;
10 void swap(int&, int&);
11 //void swap(int, int);
12 
13 int main(){
14     bool flag = true;
15     
16 lable:
17     cout<<"hello world!"<<endl;
18 
19     if(flag){
20         flag = !flag;
21         goto lable;
22     }
23     
24 
25     return 0;
26 }

ps:这里的lable标签只起到标示作用,并不影响程序的顺序执行。所以这里输出了两次hello world!。

原文地址:https://www.cnblogs.com/luckygxf/p/3980956.html