Page 77 - Touchcode_C6_Flipbook
P. 77
NESTED LOOP
Any loop in a program may contain another loop inside it. When there is a loop inside another
loop, it is called nested loop. A nested loop is helpful in case if you are working on multiple
conditions. There is no restriction on the number of loops to be nested inside a loop.
How Nested Loop Works
When the condition is true the outer While (Loop-Condition)
loop triggers the inner loop. This { While (Loop-Condition)
loop then executes normally until
its condition becomes false. Once {
the inner loop stops execution, Statement 1;
the outer loop starts again the Statement 2;
entire process is repeated until
the condition in the outer loop is }
falsified. } Inner Loop
Let’s take an example of the Outer Loop
analogue clock, it has three hands.
All the hands work in coordination with each other. The minute hand is the outer loop and
the second hand is the inner loop. When the second hand completes one revolution, the
minute hand moves by a minute. So, you can say that clock is another form of nested loop
and this is how nested loops work in real life.
Coding Task 01 Creativity
Building a Music Player
In this task, you will create a music player and learn to implement the concept of
increment loops with the help of the MakeCode Arcade platform.
To perform the task, follow these steps:
Step 1: Open MakeCode, click on 'New Project'. Write the name of project 'Building a
music player', and click on 'Create'.
Step 2: Click on 'Loops', and select 'repeat' block, drag it to the workspace and drop the
'repeat' block to 'on start' block.
Loops Using Block Coding 75

