您的位置:首页 > 编程语言 > Go语言

goto 语句(虽然不提倡使用goto 但是比赛的时候还蛮好用滴)

2016-01-02 19:47 441 查看
/// goto part2;

///part2: printf("Refined analysis:\n");

///格式 goto <标号>;

///其中标号需要申请,在程序开头写label <标号1>,<标号2>,……;

///其中,标号必须为四位以内的正整数。

///在该段落内还需要有<标号>:语句 表示将要转向的方向。

if (size>12)

goto a;

goto b;

a:cost = cost * 1.05;

flag=2;

b:bill = cost *flag;

等价于

if(size>12)

{

cost = cost * 1.05;

flag=2;

}

bill = cost *flag;

//

if(ibex > 14)

goto a;

sheds = 2;

goto b;

a: sheds= 3;

b: help = 2* sheds;

等价于

if(ibex > 14)

sheds=3;

else

sheds=2;

help = 2*sheds;

//

readin: scanf("%d", &score);

if(score > 0)

goto stage2;

lots of statements;

goto readin;

stage2: more stuff;

等价于

scanf("%d", &score);

while(score <= 0)

{

lots of statements;

scanf("%d", &score);

}

more stuff;

就这些了 呵呵哒
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: