Page 24 - Touchcode_C8_Flipbook
P. 24
While Loop/Conditional loop
While Loop executes a statement or group of statements till a given condition is true. Once
the condition turns false then the loop gets terminated.
Subject Enrichment
Example 1: To print numbers from 1 to 10.
Condition: Write numbers from 1 to 10.
Decision: Have we reached number 10?
Pseudocode:
Program Start
set a to 0
while a is less than 10
increase the value of a by 1
display a
Program End
For Loop
For loop is used to repeat a sequence for specific number of times.
Subject Enrichment
Example 2: To calculate the square of a numbers present in a list.
Numbers= [2, 4, 6, 8, 13]
Pseudocode:
Program Start
set sq to 0
for x in numbers
sq= x * x
print(sq)
Program End
Coding uiz 02 Critical Thinking
Fill in the blanks.
a. Loops make the code more ........................... and organized.
b. While and ........................... are the different types of loops.
22 Touchcode-VIII

