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?
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.
Get Adventures in Coding now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.