O'Reilly logo

Adventures in Coding by Chris Minnick, Eva Holland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

image

IN THIS ADVENTURE, you learn about blocks that make decisions and create different kinds of loops besides the simple forever loop that you saw in previous adventures.

Understanding Code Nesting

The blocks you learn about and work with in this adventure are the C-blocks. The forever block that you used in the previous adventures is an example of a C-block. C-blocks wrap around other blocks to control when and whether the blocks inside of them are executed.

Figure 3-1 shows an example of a C-block wrapped around a move () steps block and a turn clockwise () degrees block. Without running this script in Scratch, can you guess what it will do?

image

Figure 3-1 A C-block

Now try building and running the script in Figure 3-1 to see if you were right about what it does! If you guessed that it moves the sprite in a circle, you’re right!

When code fits inside of other code like this, programmers call it nesting. Think about a bird inside a nest. Now, think about a nest with a nest inside of it, with a nest inside of that, with a bird in that nest. In the bird world, this might never happen, but it happens all the time in programming.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required