1 minute read
4.5 BREAK, CONTINUE AND GOTO
4.5 BREAK, CONTINUE AND GOTO
4.5.1 BREAK
Advertisement
Break is used to exit a loop at any time or to stop running a loop. For example below, the do-while loop will run, as long as i>0. If an ‘IF statement’ states that i=6, the do-while loop must stop (break).
Figure 4.8: Example Program and Output of Break Statement
4.5.2 CONTINUE
With continue, it is possible to skip the rest of the commands in the current loop and start from the top again. The loop variable must still be incremented.
Figure 4.9: Example Program and Output of Continue Statement
4.5.2 GOTO
A goto statement in C programming language provides an unconditional jump from the goto to a labelled statement in the same function.
Figure 4.10: Example Program of Goto Statement