Page 178 - Computing E-Book Grade 6
P. 178
The City School 2021-2022
7.3. Repeat Loops
When building Minecraft, we use repeat loops to place all the initial materials for
creating a new world. That’s thousands and thousands of blocks. We also use loops in
little ways, for example, to make Alex’s feet move back and forth as she walks. Repeat
loops are a powerful part of programming.
Night is coming so in the next couple of levels, we’re going to build a house to stay
safe. We’re going to use the repeat block to do this very easily. To build a wall of our
house, we can either tell Alex to moveForward(); and place planks four times
or we can tell her to moveForward(); and place one plank, then take this command
and use the repeat block to have her perform the action multiple times. Now we’ll click
on the repeat block and tell her how many times we want her to perform this action.
7.4. If Statements
If statements are a fundamental part of learning to program. They help a computer
make decisions. All computers use if statements, including my phone. For example,
when I unlock my phone, it runs some code that says if I enter the password correctly,
then unlock the phone. Otherwise, it shows an error message.
You can use if statements in your code to make Steve and Alice react to what they see
in the world. For example, if there is a rock in front of them, they can turn left. Or turn
right if they run into a tree. In this case, we don’t want to fall into the lava. It’s easy to
178

