goto statement in C

For Complete YouTube Video: Click Here

In this class, we will understand the goto Statement in C.

We have already discussed the break and continue jump statements.

goto statement

Unlike break and continue statements, goto will work with in the function.

The goto statement can jump to any statement in a function, provided that the statement has a label.

A label is just an identifier placed at the beginning of a statement.

goto statement Example

The image below is a programming example on a goto statement.

goto Statement in C Example
goto Statement in C Example

The above program is the same that we have used in the break statement to find whether the number is prime or not.

The difference is instead of break, we have used the goto statement with a label named done.

Label done is an identifier used at the beginning of the statement from where the program execution has to be started after jumping.

As the label ‘done’ is provided at the end of the loop, the program’s execution will jump to that label, and the next line will get executed.