Page 85 - 2502_Pakistan-kifayat_C-7
P. 85
The program will be
Fill Colour Fill Colour
Move 1 step and fill colour Repeat 3 times
Move 1 step and fill colour (Move 1 step and fill colour)
Move 1 step and fill colour
Turn left Turn left
Move 1 step and fill colour Repeat 2 times
Move 1 step and fill colour (Move 1 step and fill colour)
Turn left
Move 1 step and fill colour Turn left
Move 1 step and fill colour Repeat 3 times
Move 1 step and fill colour (Move 1 step and fill colour)
Program without a loop Program with a loop
Uses of Loop
Loops provide the following advantages:
They save time.
They reduce repetition.
They make the script easier to read.
They help perform tasks quickly.
They reduce chances of mistakes.
They are used in games, apps, and websites.
They help control devices like robots and machines.
TYPES OF LOOPS
Loops are classified on the basis of how many times they repeat — one is finite and the other is
infinite.
Loop
Finite Loop Infinite Loop
Finite Loop
A finite loop is a type of loop that repeats a set of instructions for a fixed number of times. This means
the number of repetitions is known in advance. Finite loops are useful when you want an action to
happen only a specific number of times. For example, if a robot needs to jump five times, a finite loop
can be used to repeat the "jump" instruction exactly five times and then stop automatically.
#Logical Reasoning 83

