Page 73 - Touchcode_C6_Flipbook
P. 73
INCREMENTING A LOOP
Loops execute a block of code repetitively till the specified condition remains true. Each
time the loop runs, the condition is checked with the help of the loop's control variable.
Control variable is used to prevent the loop from running forever as that can cause an
infinite loop. As soon as the condition results in false, the execution of the loop stops.
Whenever the condition is true, the block of code executes. Moving to the next iteration, you
need to increase the value of the loop control variable. This is called incrementing a loop.
Subject Enrichment
Example 1: To print numbers from 1 to 10.
Flowchart:
Start
num = 1
No
If num <= 10
Yes
Print num
num = num + 1
End
Most loops have a variable called a counter variable, which keeps track of how many times
the loop is executed.
DIFFERENT TYPES OF LOOPS
Loop runs a statement or group of statements multiple times till the given condition is true.
There are different types loops. Although they perform the same task, but their working is
different. Let us take a look at the types of loop.
Loops Using Block Coding 71

