Page 76 - CloudGPT_C8_Flipbook
P. 76
Subject Enrichment
Example 3: To print a statement four times after that print a different statement.
Condition: Till the time the test expression remains true, the body of while loop prints
statement 1 and after the condition is false, it will print statement 2.
Decision: Have we printed statement 1 four times, if yes then print statement 2.
Pseudocode:
Program Start
set a to 0
while a is less that 4
increase the value of a by 1
display Hello
display world!!
Program End
Example 4: To print number from 5 to 1. Subject Enrichment
Condition: Till the time the test expression remains true, the body of the while loop printing
statement will run and once the condition is false the loop will stop executing.
Decision: Have we printed 1?
Pseudocode:
Program Start
set a to 5
while a is equal to 1
display the value of a
decrease the value of a by 1
Program End
For Loop
The for loop is used to repeat a sequence a specific number of times.
Example 1: To print a statement six times using the 'for' loop. Subject Enrichment
Pseudocode:
Program Start
for value a in range 1 to 6
74 Premium Edition-VIII

