The goto statement is used to alter the normal sequence of execution of a C program by shifting the control to a different part of the same program.
The syntax of goto statement in C programming language is :
goto label;
-------------
-------------
-------------
label :
statement;
-------------
-------------
-------------
label :
statement;
Example :
#include <stdio.h>
int main()
{
int main()
{
int sum=0;
for(int i = 0; i<=10; i++){
sum = sum+i;
if(i==5)
{
goto addition;
}
for(int i = 0; i<=10; i++){
sum = sum+i;
if(i==5)
{
goto addition;
}
}
addition:
printf("Result : %d",sum);
return 0;
}
addition:
printf("Result : %d",sum);
return 0;
}
Output :
Result : 15
0 Comments