Introduction to C
Data Types in C
Operators in C
Hello World Program
Loops in C
Single Dimensional Array
Two Dimesnional Arrays
Array Example Programs
The goto statement is a jump statement which jumps from one point to another point within a function. It is marked by a label statement that can be that can be used anywhere in the function above or below the goto statement.
Let us understand its working by writing a simple program in C.
C Program to print 1 to 5 using goto statement in C
Explanation for the above program
Here in this program, we are displaying output from 1 to 5. See the above program. We have initialized a variable i equal to 1. Also, there is a label statement 'loop' defined above goto statement. Now, firstly it will print the value of i as 1 from the printf statement. Now, value of i will be incremented by i+1 as i++ is there after printf. Now, value of I is equal to 2. It will check the if condition as if i<5 or not. Condition is true since currently value of i equals to 2. So, it will come inside if and execute goto statement which says to go to loop. It will go to loop and start executing from there. Then, value of I will pe printed from printf statement. Similarly, 1 to 5 will print as output there.
Note: If find any issues/errors with the tutorial above, please immediately mail it to firstname.lastname@example.org