togo

来源:互联网 发布:php 二进制 编辑:程序博客网 时间:2024/06/07 07:34

某位大神不推荐使用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;    }



0 0