1 minute read

4.1 LOOPING STATEMENT

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:

Advertisement

Figure 4.0: Types of Looping Statement

Each loop must consist of initialization, condition and counter.

Figure 4.1: Initialization, Condition and Counter

for

• loops from one number to another number and increases by a specific value each time

while

• 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

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

This article is from: