Unconditional Branching (goto)
Goto :
- Goto statement provides a way for unconditional branching.
- It used to jump or switch program execution control from one location to other location(anywhere) in a program.
- Syntax : goto label;
- Here goto instructs a computer to jump at location where label is specified in a program.
- Example Let's consider following block of code:
#include<stdio.h>
int main()
{
int num;
labe1:printf("Number is Even");
label2:printf("Number is Odd");
labe1:printf("Number is Even");
label2:printf("Number is Odd");
printf("Enter number:");
scanf("%d",&num);
if(num%2==0)
goto label1;
Else
goto label2;
return 0;
}
- Here we are printing result using goto statement.
- Here we are printing result using goto statement.
Comments
Post a Comment
Please do not enter any spam link in message.