您的位置:首页 > 编程语言 > C语言/C++

C语言goto语句

2016-07-20 09:27 302 查看

C语言goto语句

C语言goto语句实例代码教程 - goto语句在C编程语言提供的goto无条件跳转到带标签的语句相同的功能。

goto语句在C编程语言提供的goto无条件跳转到带标签的语句相同的功能。

注意:强烈建议不要使用goto语句在任何编程语言,因为它使得难以追踪程序的控制流,使程序难以理解和难以修改。可以重写任何程序,使用一个goto,因此,它不需要goto语句。


语法:

在C语言中 goto语句语法如下:
goto label;
..
.
label: statement;


标签可以是任何纯文本,除C关键字,它可以被设置高于或低于goto语句在C程序中的任何地方。


流程图:



例子:

#include

int main ()
{
/* local variable definition */
int a = 10;

/* do loop execution */
LOOP:do
{
if( a == 15)
{
/* skip the iteration -by www.yiibai.com*/
a = a + 1;
goto LOOP;
}
printf("value of a: %d\n", a);
a++;

}while( a < 20 );

return 0;
}


上面的代码编译和执行时,它会产生以下结果:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: