Welcome back to Scratch. Just to quickly review where we left off, please answer each of the following questions, based on the labels A, B, C, D, E and F in the image below.
- Which labelled area is the stage?
- Which labelled area are the sprite tabs in?
- Which labelled area are the tabs for blocks in?
- Which labelled area is the scripts area?
- Which labelled area is the sprite?
- Which labelled area is the blocks area?

Let us make a song in Scratch with the following script. Double-click it to play!

It is definitely a bit of work to make copies of the same block repeatedly to do the same thing. It would be nice if there were a faster way to do the same thing. This is a common thing for computer scientists to do. Rather manually doing a task repeatedly, we would like to tell the computer to repeat the task the number of times we would like. Let us now use a trick for repeating something multiple times. In the Controls tab, you will find a block labelled repeat. Use the repeat and the play note blocks to create the script below.

If we want to rewrite the script in Figure 30 using a repeat block, what number should go in the blank in the repeat block? I hope you will agree that this saves us a lot of time. So far, when we wanted to do something over and over again, it took a lot of work and a lot of blocks. To make our work easier, we use repeat blocks! A repeat block run code over and over again. The number next to the word repeat tells us how many times we want to do the things inside of the repeat block.
6.1 Experiment with Repeat
Try to make scripts that uses different numbers after the repeat. Here are some examples.

Try to put blocks before, after, and inside the repeat, like below.

Try making other scripts with repeat. Do not delete each script that you make. Leave them in the scripts area and use new blocks to make new scripts. Hint: If you click on a block with the right button on the mouse ("right-click"), you should see "duplicate", "delete" and "add comment" options. Select "duplicate" to make a copy of the block you clicked on and all blocks below that block. If right clicking does not work, you can press shift and then click to see the menu.

6.2 Nested Repeats
We can put one repeat inside of another repeat! We call this a nested repeat.

In the above example, the outside repeat tells the inside repeat to run two times. This mean the note 62 is played twice three times, or in other words 3 times 2 = 6 times. Play around with the values in both repeats until you understand how many times the play note runs due to these values. What if the inside repeat value is zero?
6.3 Complex Nested Repeat
Nested repeats (a repeat within a repeat) can become complicated! We need to learn how to keep track of them. Let us look at the following example.

When you run the above example, first note 55 plays once and then note 65 repeats 5 times. After this note 55 plays again once, followed by note 65 again 5 times. This process repeats 4 times. Being able to figure out exactly what happens when you have multiple repeats or nested repeats can be really important.
In the following script, how many times does the note 52 play when you double click the script? How many times does the note 60 play when you double click this script? Which note plays first? Which note plays last?

6.4 Tricky Nested Repeat
It is important in computer science to figure out exactly what instructions execute when a script runs and in what order. The exact order in which instructions execute in Scratch or any programming language matters because the final output can change completely based on this order.

These four questions are all about the script above.
- When the script is run, what is the first note that is played?
- When this script is run, what is the last note that is played?
- When this script is run, is the note 40 ever played twice in a row?
- When this script is run, is the note 60 ever played twice in a row?
When this block is doubled clicked, will you hear the sound of the instrument?
Excercise:
- Answer the following questions about the script given below
- - Can we make the script simpler?
- - What is the smallest number of blocks needed to make a script that has the same output?
- - What is the value of the repeat block?
- - Does the note 60 occur inside the repeat block?
- - Does the note 65 occur inside the repeat block?
- How many times does the note 61 play when you run the script below?
- How many times does the drum 13 play when you run the script below?
- The next two questions are about the following script.
- How many times does the note 58 play when you run the script above?
- How many times does the note 48 play when you run the script above?
- Write the order in which the notes play when you run the script. Write the numbers corresponding to the notes in order, separated by spaces. We have started the list off for you.
50 60 70 ________________________________
What numbers go in the blank to complete the list of notes played? (Do not include the first 50 60 70).




