Beginner Coding with Blocks
Chapter
>
Level
Loops and Repetition
For Loop Sequence
Objective
Collect grains and make your way out of the maze by using no more than four (4) blocks.
You've found yourself lost in the middle of a maze, use loops in order to collect the grains in the field and exit the maze.
As you can see from the map the maze is uneven so you can't just repeat the same movement like in previous levels. For this you need to make full use of the for loop block's variable.
Use the for loop block with a variable named x. Set it to start from 0 and go to a number (like 11). The variable x checks how many cycles the for loop block has gone through. By using the variable x in the move forward block's steps parameter (using a math block to add x + 1), this will allow you to move your character one more step each time the loop cycles.
For example, if you set the for loop block to go from 0 to 3, and use x + 1 in the move forward block's steps, the movement will increment an extra step each time the loop cycles, and would look like this in practice:
- First Loop:
move forward(1 step) - Second Loop:
move forward(2 steps) - Third Loop:
move forward(3 steps) - Fourth Loop:
move forward(4 steps)
Use the variable from the for loop block inside the move forward block's steps parameter to increment your movement each loop and collect all the grains to complete the level. Remember, this must be done by using no more than four (4) blocks.