lesson

Updated 6 days ago ยท 1 view
If you tell a robot to "make toast," it won't know where the bread is, how to push the lever, or when to catch the slice.
Computers do not guess โ they follow a sequence, which is an exact, step-by-step order of instructions from top to bottom.
๐Interactive diagram
What happens when your character needs to walk around an entire square soccer field? Do you stack dozens of identical blocks?
Repeating with Loops
Instead of snapping together 20 identical blocks, we use a loop, a special container block that repeats instructions automatically.
Programmers call each complete run through a loop an iteration, which simply means one round of repeating.
The number parameter inside a repeat block determines the loop count. For example, putting a Hop Up block inside a Repeat block set to 3 executes Hop Up 3 times.
๐Interactive diagram
The number parameter inside a repeat block determines the loop count. For example, placing a Hop Up block inside a Repeat block set to 3 executes Hop Up 3 times.
Let's put this into action with a real design challenge: collecting 4 energy gems placed at the corners of a grid.
Design Challenge: The Gem Patrol
To visit all 4 corners and return home, our sprite needs to perform two actions four times: move forward 3 steps, then turn right 90 degrees.