PROGRAMMING FUNDAMENTALS 4.1
LOOPING STATEMENT The repetition (or iteration) structure permits a sequence of the instructions to be executed
repeatedly until certain condition is reached. Looping statement are used to execute a set of statement repeatedly based on condition. Three types of looping are as below:
for
while
• loops from one number to another number and increases by a specific value each time
• can be used if you don’t know how many times a loop must run
do-while • do something first and then test if we have to continue. The result is that the loop always runs once
Figure 4.0: Types of Looping Statement
Each loop must consist of initialization, condition and counter.
Initialization
The initialization is an assignment statement that is used to set the loop control variable Condition The condition is a relational expression that determines when the loop exists Counter The increment defines how the loop control variable changes each time the loop is repeated Figure 4.1: Initialization, Condition and Counter
44 | P a g e