#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int i;
num:printf ("a ");
for (i = 0;i < 10;++i)
{
goto num;
}
system ("pause");
return 0;
}
请问为什么会出现死循环啊,希望详细讲解一下goto语句的用法。谢谢!
非常详细,num:printf ("hello");在没用goto语句调用它标号的时候他也会执行一次吗?
#include
#include
int main (void)
{
num:printf ("hello\n");
goto num;//请问怎么才能让goto只跳转一次呀,谢谢!
system ("pause");
return 0;
}
问题1:num:printf ("hello");在没用goto语句调用它标号的时候他也会执行一次吗?
答:会执行的.这个语句是正常的代码 只不过加了一个标志,这个标志并不对代码造成任何影响.
问题2:请问怎么才能让goto只跳转一次.
答:goto本身就只是跳转代码的功能,如果硬要让他只执行一次,那就加个if条件语句好了..
#include
#include
int main (void)
{
int n=0;
num:printf ("hello\n");
n++;
if(n<2) goto num;
system ("pause");
return 0;
}
//第一次执行到num处时,打印"hello\n",接着n++为1,符合if条件,进行goto跳转到num,打印"hello\n",然后n++为2,不符合if条件..不进行goto了... 完成只跳转一次的功能!
程序执行到goto num的时候就直接跳出for循环啦?有什么办法能让goto在for循环里执行goto语句后面的部分呀?谢谢!