#include <stdio.h>
int main()
{
while(1)
{
printf("hehe\n");
goto end; //goto 语句可用于跳出死循环,强制跳转到指定字符处
}
end: //指定字符后加冒号
return 0;
}
int main()
{
int i = 0;
int j = 0;
for (i = 0; i < 100; i++)
{
for (j = 0; j < 100; j++)
{
printf("heh\n");
goto add; //或用于跳出深层循环
}
}
add:
return 0;
}
//注意,goto语句不可随意使用,尽可能少量的使用
//因为强制跳出有可能造成循环紊乱
C++ goto语句
2023-12-15 09:34:02 27 阅读