In this article we will discuss about goto statement of C in which following topic are included.
- Goto statement in C
- types of jump statement
- Example of goto statement
Goto Statement in C :
C support the goto statement to branch unconditionally from one point to another in the program or in another words we can say that goto statement is also a type of jump statement with help of which a programmer can be transferred the control from point to another point in the program.
The goto statement require a labels in order to identify the place where the branch is to be made. A label is any valid variable name, and must be followed by colon. The label is placed immediately before the statement where the control is transferred.
The general forms goto and label statement are shown below:
Syntax of goto function:
Forward Jump:-
goto label;
..................
..................
..................
label:
statement;
Backward Jump:-
goto label;
...................
...................
...................
label:
statement;
Note:- A goto statement break the normal sequential execution of the program. if label is before the statement goto label; a loop will formed and some statement will be executed repeatedly. Such a jump is know as backward jump.
On the other hand ,if label is placed after the goto label some statements will be skipped and the jump is know as forward jump.
Example of goto statement in C :
#include<stdio.h>
int main()
{
double x,y;
read:
scanf(" %f ", &x);
if(x<0) goto read;
y=sqrt(x);
printf(" %f %f \n ", x , y);
goto read ;
}
Conclusion:
In this article we have leaned about goto statement in detail with example , I hope after reading this article you have no any doubt remaining in this topic but still if you have any doubt then feel free comment below.
