c语言中有没有goto语句_C语言中的goto语句

c语言中有没有goto语句

goto statement in C

By using goto statement you can transfer the control of program anywhere. This keyword is not recommended to use in any situation. 

Syntax


goto label;
. . . . 
. . . . 
label: statement;

Flowchart of goto statement in C – Image Source

Lets make one program to understand it.

#include<stdio.h>
 
void main()
{
 int i=1;
 
 if(i==1)
  goto one;
 else if(i==2)
  printf("2");
 else
  printf("Its nothing");
 
 one:
 printf("Avoid goto keyword");
}


Output


Why you should avoid goto statement in C?
It takes the control of the program anywhere and anytime which is not good for software development life cycle. In this cycle a program has to debug and re-test a lot of times. And with the use of goto keyword it makes very hard to debug the program.

This keyword is generally used to take the control outside the loop. That’s it. Otherwise you should avoid this keyword.

goto statement in C

By using goto statement you can transfer the control of program anywhere. This keyword is not recommended to use in any situation. 

Syntax


goto label;
. . . . 
. . . . 
label: statement;

Flowchart of goto statement in C – Image Source

Lets make one program to understand it.

#include<stdio.h>
  
 void main()
 {
  int i=1;
  
  if(i==1)
   goto one;
  else if(i==2)
   printf("2");
  else
   printf("Its nothing");
  
  one:
  printf("Avoid goto keyword");
 }


Output


Why you should avoid goto statement in C?
It takes the control of the program anywhere and anytime which is not good for software development life cycle. In this cycle a program has to debug and re-test a lot of times. And with the use of goto keyword it makes very hard to debug the program.

This keyword is generally used to take the control outside the loop. That’s it. Otherwise you should avoid this keyword.

翻译自: https://www.thecrazyprogrammer.com/2015/01/goto-statement-in-c.html

c语言中有没有goto语句

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值