某位大神不推薦使用togo,認為togo使代碼變得混淆、不易理解。在此簡單介紹下togo的用法。
int a = 1; start:{ a++; NSLog(@"%d",a); } if (a<5) { goto start; }else{ goto end; } end:{ NSLog(@"GG"); }
這種用法是正確的。
為什么toog語法一定要寫在中間,這和代碼的執行順序有關。我們來看下togo放在不同位置時輸入的結果。
int a = 1; if (a<5) { goto start; }else{ goto end; } start:{ a++; NSLog(@"%d",a); } end:{ NSLog(@"GG"); }
int a = 1; start:{ a++; NSLog(@"%d",a); } end:{ NSLog(@"GG"); } if (a<5) { goto start; }else{ goto end; }
新聞熱點
疑難解答