goto语句
C语言
goto语句又叫无条件转移语句,先看一个例子:
#include <stdio.h>
void main()
{
if ( 1 )
{
goto gotoflag;
}
printf( "hello " );
gotoflag: printf( "nihao" );
}
输出的结果为:nihao
可以看出在执行 goto gotoflag 语句之后直接跳转到gotoflag:printf(“nihao”);
gotoflag:为标记行,冒号切记不可省略。
反之如果代码这样子
#include <stdio.h>
void main()
{
if ( 0 )
{
goto gotoflag;
}
printf( "hello " );
gotoflag: printf( "nihao" );
}
输出的结果为:hello nihao
此时gotoflag将没有意义