Page 73 - Digicode_AI_class_7
P. 73
For Loop
The for loop is used to repeat a sequence a specific number of times.
Example: To print a statement six times using the ‘for’ loop.
Pseudocode:
Program Start
for value a in a range 1 to 6
display ‘I want to play’
increase the value of a by 1
Program End
Example: To print all the odd numbers from a list using for loop.
Pseudocode:
Program Start
list1 = [12, 25, 8, 50, 75, 30]
for a in list1
if a % 2!= 0
print(a, end = ‘ ‘)
Program End
Nested Loop
When there is a loop inside another loop, it is called a nested loop. When one loop is nested within
the other, the execution of the entire program depends on the execution of the innermost loop. The
outer loop cannot complete its execution until the inner loop has finished its execution.
Entry Criteria
Entry criteria is a check for a looping condition, which needs to be true to ensure that the loop runs.
Entry criteria is a condition which must be true or must met or must exist before starting a specific
task. Criteria can be different from program to program as per the requirement.
Let’s understand the concept of entry criteria, by taking an example of starting a bike. To start a
bike you need petrol in the fuel tank. If your fuel tank is empty your bike won’t start. So, in this case
the entry criterion to start the bike is that the fuel tank should not be empty.
Exit Criteria
A looping condition must get false at a certain point of time, else the block of code will enter in an
infinite loop. For this it is important to define an exit criterion for the loop.
An exit criteria is a condition which must be met before completing a specific task. It is a set of
conditions that must exist before when you can declare a program to be complete.
Exit criteria differ from program to program as per the requirement.
Let’s understand the concept of exit criteria, by taking an example of creating a loop to print numbers
th
from 1 to 100 exit criteria in this situation, is that the loop should exit the block of code when the
th
100 number is printed, else the program will enter in an infinite loop.
More on MakeCode Arcade 71

