Linux C编程 - goto 的基本用法
goto 的基本用法
goto语句有两个部分: goto和标签名。标签的命名规则与变量的命名规则一样。例如:
goto test;
为了让这条语句能正常工作,函数还必须包含另一条标为test的语句,该语句以标签名后紧跟一个冒号开始,例如:
test:
printf("go to test\n");
goto 的使用例子
#include<stdio.h>
void TestGoto(void)
{
int i = 0;
while(1)
{
for (i = 0; i < 10; i++)
{
if (i > 5)
{
goto test;
}
printf("==>UDEBUG %s:%d i = %d\n", __FUNCTION__, __LINE__, i);
}
}
test:
printf("i = %d, test goto end!\n", i);
}
int main()
{
TestGoto();
return 0;
}
==>UDEBUG TestGoto:14 i = 0
==>UDEBUG TestGoto:14 i = 1
==>UDEBUG TestGoto:14 i = 2
==>UDEBUG TestGoto:14 i = 3
==>UDEBUG TestGoto:14 i = 4
==>UDEBUG TestGoto:14 i = 5
i = 6, test goto end!
相关推荐
-
nginx检查提示“unknown directive "stream" in /etc/*/nginx.conf”
nginx检查提示“unknown directive "stream" in /etc/*/nginx.conf”2025-02-26 00:38:21 -
php之多级目录下查找文件中是否含有某个字符串功能实现2025-02-26 00:36:35
-
mysql 启动不了1067错误如何解决?2025-02-26 00:33:31
-
MySQL简单INSERT超慢原因排查2025-02-26 00:22:42
-
mysql分布式数据库的主要构架是什么?2025-02-26 00:06:23