C++(Goto使用实例)
生活随笔
收集整理的這篇文章主要介紹了
C++(Goto使用实例)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于很多技術,看源碼很重要,但還是看實例代碼進步最快~
代碼片段一:
#include <iostream> using namespace std; int main(){int val = 0;for (int i = 0; i < 100; ++i){for (int j = 0; j < 100; ++j) {val = i * 100 + j;if (val > 520) goto BUTTON;}}cout << "OutPut 1\n";BUTTON: // 這里關鍵cout << "Hello, Here is the "<< val<< "th.\n";cout << "OutPut 2\n"; }輸出的結果:
Hello, Here is the 521th.
OutPut 2
看到這個我想到了,匯編代碼中的實例 哈哈哈
實例代碼二
#include <iostream> using namespace std; int main(){int val = 0, i;for (i = 0; i < 100; ++i){for (int j = 0; j < 100; ++j) {if (val > 520) goto BUTTON;val = i * 100 + j;}BUTTON:if (i > 20) goto BUTTON2;}cout << "OutPut 1\n";BUTTON2:cout << "Hello, Here is the "<< val<< "th.\n";cout << "OutPut 2\n";cout << "i = "<< i<< endl; }Hello, Here is the 521th.
OutPut 2
i = 21
總結
以上是生活随笔為你收集整理的C++(Goto使用实例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TCP实现在不同局域网下的两台电脑网络通
- 下一篇: [解析]多线程加锁Lock调用pytho