goto Statement in C
About C goto statement:
On this page we will discuss about C goto statement with it’s syntax and example.goto statement is a jump statement , it is used to transfer the program control from one location to another location.It is also knows as unconditional jump statement.It can alter the normal flow of code.goto statement is usually avoided because it increace the complexity of code.
What is C goto statement ?
In C language, goto statement is used as unconditional jump statement which is used to jump from one statement to another statement at another location.Using goto statement you can jump to above and below the current code flow.when can use goto statement when we want to exit the nested loops or multiple loops instead of break statement for each loop.
goto label; ... .. ... ... .. ... label: statement;
Here, label cannot be the keyword.Basically label is an identifier.When goto is encountered the flow of code is trasnfered from that statement to label: and the statements below it gets executed.
value of k: 12 value of k: 13 value of k: 15 value of k: 16 value of k: 17 value of k: 18 value of k: 19 value of k: 20 value of k: 21 value of k: 22 value of k: 23 value of k: 24
Disadvantages of goto statement :
- Since,goto statement is a unconditional statement,the efficiency of the program reduces by moving the control from one point to another unconditionally.
- goto statement can be use to move the control up or down which may lead to infinite loop.
- If we increase the number of goto statement in a program then the tracing become difficult.
x:statement-1; statement-2; statement-3; goto x;
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others