Beginner Coding with Blocks
Chapter
>
Level
Conditions and Decisions
Loop Conditions
Objective
Collect and dump all the weeds in the passages using loop conditions using no more than twelve (12) lines of code.
The path to the courtyard is full of weeds that need to be taken care of. You can automate this process by using loops and using the else section of if blocks to their fullest.
The passages around the courtyard is full of weeds, collect them and use the place block to dump them in a container at the end of each passage. This should be easy with loops however, there are three (3) passages, two of these passages have nine (9) weeds, one has five (5).
Create a for loop block with variable x from 0 to 2 so the code inside the loop can encompass all three (3) passages.
Use the for loop block. Inside the loop, move forward 10 steps, then use an if block with an else section. Check if x equals 0 using the equals comparison block.
There are five (5) weeds in the first passage and nine (9) in the other passages, use an if block to check if the loop is in its first cycle by checking if x is equal to 0. Remember the x variable is what checks what cycle the loop is in and it always starts at 0.
If the if condition is true, create a variable named bag and set it to 5, then use the place block to dump the weeds at the X mark, and turn right. Use the else section to run a variation of the same code but set bag to 9 if the condition is not met (i.e., when x is 1 or 2).
Complete the level by collecting all weeds and placing the correct number of them in each container using no more than twelve (12) lines of code.