Programming Fundamentals

Page 52

PROGRAMMING FUNDAMENTALS 4.5

BREAK, CONTINUE AND GOTO 4.5.1

BREAK 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 48 | P a g e


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.