goto语句:
01 tryagain:
02 int res = doSomething();
03
04 //......
05
06 if (res < 0) {
07 goto tryagain;
08 }
09 else{
10 doSomething2();
11 }
替代方法,用do{} while(0)替代:
01 do{
02 int res = doSomething();
03
04 //......
05
06 if (res < 0) {
07 continue;
08 }
09 else{
10 doSomething2();
11 }
12 }while(0);
还有这种goto:
01 int res = doSomething();
02
03 //......
04
05 if (res < 0) {
06 goto errorOccur;
07 }
08 else{
09 doSomething2();
10 }
11
12 errorOccur:
13 doThing();
换成这种:
01 do{
02 int res = doSomething();
03
04 //......
05
06 if (res < 0) {
07 break;
08 }
09 else{
10 doSomething2();
11 }
12 }while(0);
13
14 doThing(); |