Repeating Patterns with Loops
Grade 2, Grade 3Lesson 2 of 10 in Computing and Coding for Ages 7 to 11 Course
What you will learn
- Find the steps that happen again and again, use a repeat block to run them as many times as you need, and see how a loop makes a program shorter and easier to change.
- Find the part that repeatsLook at a list of steps in a song, a dance, a path or a program, find the group of steps that repeats, and count how many times it comes.
- Make a repeat block run your stepsPut blocks inside a repeat block, set how many times it runs, and say what happens before, during and after the loop.
- Make programs shorter and easier to changeRewrite a long program with a loop, count how many blocks you save, and see why shorter code is easier to read, change and fix.
- Find the part that repeats
- Use repeat blocks to draw shapes with equal sides, and make repeating patterns with lines, sounds and number jumps.
- Draw shapes with equal sidesProgram a sprite or turtle with a pen to draw squares, triangles and other shapes with equal sides by repeating a move and a turn.
- Make patterns with lines, sounds and number jumpsUse a loop to make dashed lines, staircases, drum beats and number patterns, such as counting by threes on a number line.
- Draw shapes with equal sides
- Understand nested loops, count how many times each part runs, and use them to build bigger designs out of repeated shapes.
- Understand how a loop inside a loop runsRead and run a loop inside another loop, and work out how many times each block inside it runs.
- Build designs from repeated shapesUse an inner loop to draw a shape and an outer loop to repeat that shape in a row or around a point.
- Understand how a loop inside a loop runs
- Use a forever loop for actions that should keep going until you stop the program, choose between forever and repeat, and make sprites move and change in simple animations.
- Choose a forever loop or a repeat loopKnow what a forever loop does, how it stops, and when to use it instead of a repeat block with a number.
- Animate a sprite with loopsMake sprites seem to move by repeating costume changes, small moves and short waits, with a repeat block or a forever loop.
- Choose a forever loop or a repeat loop
- Read a program with loops and say what it will do before you run it, then test it and find and fix loop bugs one step at a time.
- Predict what a loop will doRead a program with loops, work out what it will draw, play or say and how many times each block runs, and then run it to check.
- Find and fix bugs in loopsTest a program with loops, find the mistake when it does not do what you wanted, and fix it by changing one thing at a time.
- Predict what a loop will do
Loops in Coding study guide
1Spot repeats and use repeat blocks
You already know how to put blocks in order. Now look for steps that come back again and again. You will find a repeating group, wrap it in a repeat block and follow every round. Then you will compare a long stack with a shorter loop and check that both do the same job.
1.1 Spot the repeating group
A dance can have lots of steps but only one short pattern. When you spot that pattern, you can give much shorter instructions.
Look for matching groups
An instruction tells you one step to do. A sequence puts steps in order. A repeating pattern has a group that comes again in the same order. Repetition means doing something again. Another name for it is iteration. In a program, a loop repeats instructions.
Try saying this dance aloud:
"Clap, clap, stomp, clap, clap, stomp, clap, clap, stomp, clap, clap, stomp."
Start with the smallest group that fits: "clap, clap, stomp." Mark each copy with a line:
"Clap, clap, stomp | clap, clap, stomp | clap, clap, stomp | clap, clap, stomp."
There are four matching groups. Each group has three actions. Adding the group sizes gives 12 actions:
The short instruction is "repeat four times: clap, clap, stomp." The repeat number counts groups. It does not count all 12 actions.
Keep the extra steps
Now try "stand up, hop, hop, hop, hop, hop, sit down." Only "hop" repeats. Say "stand up, repeat five times: hop, then sit down." You stand up and sit down once each.
A song's chorus can repeat while its beginning and ending happen once. A robot path can repeat "forward, turn right" four times. With equal forward moves and quarter turns, that path makes a square.
Check the last group too
Look at "jump, clap, jump, clap, jump, stomp." The first two groups match: "jump, clap." The ending is different. You can repeat "jump, clap" twice, then add "jump, stomp."
To find a repeat yourself:
- Write or say all the steps in order.
- Mark the smallest group that repeats exactly.
- Count the copies of that whole group.
- Leave any extra beginning or ending outside.
Key Takeaways
- A loop repeats instructions in a program.
- Count copies of the whole group, not individual actions.
- Check that the order matches in every copy.
- Keep one-time beginning and ending steps outside the repeat.
1.2 Read the inside of a repeat block
A repeat block wraps around the instructions you want to do again. Its shape helps you see which blocks belong together.
Follow one round
A repeat block often looks like the letter C. Blocks fit inside its gap. Its number tells the computer how many times to run those inside blocks. A loop with a set number is a count-controlled loop.
Read this program from the top:
say "Ready!" for 1 second
repeat 3
play drum sound
wait 1 second
say "Done!" for 1 second
The spaces show which blocks sit inside the loop. First, the sprite says "Ready!" once. Then it plays a drum and waits. That is one whole round. It goes back to the first inside block for round two. It plays and waits again for round three. After that, it says "Done!" once.
Inside, before and after
| Where the block sits | When it runs |
|---|---|
| Above the loop | Once, before the repeats |
| Inside the loop | On every round |
| Below the loop | Once, after the last round |
Drag the "Done!" block inside, below the wait, and the sprite says it three times. Its words stay the same, but its place changes what happens.
Count what happens
A loop with five rounds and a 10-step move travels 50 steps along its path:
You can also think "five groups of ten." Three rounds with two drum blocks inside make six drum sounds. The number on the repeat block counts rounds, not how many blocks fit inside.
Order matters too. repeat 2 with clap then jump gives "clap, jump, clap, jump." Swapping the inside blocks gives "jump, clap, jump, clap." The totals match, but the dance changes.
Put the whole group inside
To draw a square, the sprite must move and turn each round. If only the move is inside repeat 4, it moves four times along one straight path. A turn below that loop happens just once, at the end. Put the move and the turn inside together.
Key Takeaways
- The repeat number tells you how many rounds to run.
- Inside blocks run from top to bottom on every round.
- A block below a fixed repeat starts after the loop finishes.
- Count every copy of each inside action.
- Changing a block's place or order can change the result.
1.3 Replace copies with one loop
Copying blocks works, but a long stack can be hard to check. A loop lets you keep one copy of the repeating group.
Count blocks you can see
Drawing a square takes four copies of move 100 steps and turn right 90 degrees. That makes eight blocks in the long stack:
The loop version has one repeat block and two inside blocks:
repeat 4
move 100 steps
turn right 90 degrees
Count each visible block once. There are three blocks, even though the move and turn each run four times. The saving is five blocks:
For ten copies of "move 10 steps, play pop sound," the long stack needs 20 blocks. One repeat block and those two inside blocks need three. That saves 17 blocks. More copies mean more places where a loop can save work.
Change one place
Want a bigger square? In the long stack, change all four move blocks. In the loop, change the single move from 100 to 150 steps. Every side becomes longer. Want eight hops instead of four? Change the repeat number.
A shorter, clearer program is more efficient for the person building and reading it. Fewer copied blocks make mistakes easier to spot. One copied turn might say 80 degrees when the others say 90. A loop repeats the same turn each time. If that turn is wrong, you can fix it in one place.
Check that it still matches
Unroll a loop by writing every action in order. For repeat 3 around "forward, turn right," write:
"Forward, turn right, forward, turn right, forward, turn right."
Compare this with the long stack. Check the actions, their order and how many times they happen. A short program with only three sides still fails to draw a square.
A one-time action needs no repeat block. Wrapping it in repeat 1 adds a block without saving copies. A comment, such as "draws one square," can help a person understand a loop. The computer ignores that note.
Key Takeaways
- Count visible blocks separately from how many times they run.
- A loop lets you change all repeats in one place.
- Unroll a loop to check its actions, order and count.
2Draw shapes and patterns with loops
A sprite can draw as it moves, just like a pencil following directions. You will choose moves and turns to close a shape. Then you will build dashed lines, stairs, beats and number jumps. The same idea guides them all: plan one group, then repeat it.
2.1 Move and turn to close a shape
You can make a sprite or turtle draw by giving it a pen. A repeated move and turn can draw a whole shape.
Get ready to draw
Clear old lines. Choose a start spot and a facing direction. Lower the pen with pen down. It draws as the sprite moves. Use pen up to move without leaving a line.
move 100 steps goes forward in the direction the sprite faces. turn right 90 degrees changes that direction on the spot. It draws no side by itself. A quarter turn is 90 degrees. A full turn, all the way around, is 360 degrees.
Build a square
pen down
repeat 4
move 100 steps
turn right 90 degrees
Follow the rounds with your finger. Round one draws a side and turns. Round two draws the next side and turns. Round three draws another side. Round four draws the last side and turns back to the starting direction. The sprite returns to its starting spot.
The four turns make one full turn:
Choose the turn for each shape
A regular shape has equal sides and equal corners. For one trip around its edge, repeat once per side. Share one full turn equally between those sides:
| Regular shape | Repeats | Turn each round |
|---|---|---|
| Triangle | 3 | 120 degrees |
| Square | 4 | 90 degrees |
| Pentagon | 5 | 72 degrees |
| Hexagon | 6 | 60 degrees |
| Octagon | 8 | 45 degrees |
For a triangle, use repeat 3 with move 100 steps and turn right 120 degrees. Its three turns total 360 degrees.
The turn measures how far the sprite changes direction. The 60-degree corner inside an equal-sided triangle is different. Turning only 60 degrees three times draws half a hexagon, leaving an open path.
Change size or shape
A longer move makes each side longer. Keep the repeat number and turn the same to keep the shape. Change one number at a time and watch the result.
Changing a square to three repeats leaves one side missing. Changing it to eight repeats draws the same square twice. A tiny move repeated 36 times with a 10-degree turn makes 36 short sides. Together they look nearly round.
Left turns trace regular shapes the other way around. A five-pointed star uses five equal moves and 144-degree turns. Its turns total 720 degrees, or two full turns. Use the 360-degree rule for one trip around a regular shape's outside edge.
Key Takeaways
- Pen down draws during moves; pen up lets you travel without drawing.
- A move draws a side; a turn changes the facing direction.
- One trip around a regular shape uses one repeat per side.
- Divide 360 degrees by the number of sides to find its turn.
- The turn is a change in direction, not the inside corner.
- The move length changes the size.
2.2 Build a repeating line, beat or number path
The core of a pattern is the part that repeats. Your loop holds that core. You can repeat lines, sounds or equal jumps on a number line.
Leave a gap after every dash
Start facing right. This loop makes a dashed line:
repeat 5
pen down
move 20 steps
pen up
move 20 steps
One round draws a 20-step dash, lifts the pen, then moves through a 20-step gap. Each round travels 40 steps. Five rounds make five dashes and travel 200 steps, including the final gap.
Put pen down inside the loop. If it sits only above the loop, the first dash appears. Then pen up leaves the pen raised for all the later rounds.
Repeat one stair
With the pen down and the sprite facing right, try:
repeat 4
move 30 steps
turn left 90 degrees
move 30 steps
turn right 90 degrees
One round goes right, turns upward, moves up, then faces right again. The opposite turns get the sprite ready for another stair. Four rounds take it 120 steps right and 120 steps up. The total path is longer because it includes both the across and upward moves.
Hear the core
A beat of "drum, drum, cymbal" has three sounds. Repeating that core four times gives eight drums and four cymbals. You hear 12 sounds altogether. Keep all three sound blocks inside and keep their order.
Jump along a number line
Start at 0. Repeat a jump of 3 five times. The landings are 3, 6, 9, 12 and 15. This is skip counting: adding the same number each time.
The jumps make five equal groups of three:
Changing the repeat number changes how many jumps you take. Changing the jump size changes the distance each time. A loop drawing two dots on each of four rounds gives four equal groups of two dots.
To build your own pattern, sketch or say it first. Circle the core and count its copies. Put the whole core inside a repeat block. Run it and compare what you see or hear with your plan.
Key Takeaways
- The loop's inside blocks make the pattern's core.
- A dashed-line loop must lower and lift the pen each round.
- Opposite quarter turns let a stair end facing the starting way.
- Equal number jumps show skip counting and equal groups.
3Put a loop inside a loop
A square can be one small part of a bigger picture. You will put one loop inside another, follow the inner loop through each outer round and count its actions. Then you will repeat whole shapes, moving or turning between copies to make a row or flower.
3.1 Count a loop inside a loop
A loop can hold another loop. The inside one finishes all its rounds every time the outside one reaches it.
Name the two loops
A nested loop is a loop inside another loop. The outside one is the outer loop. The one inside is the inner loop. Nested repetition is another name for this arrangement.
Read this from the outside inward:
repeat 3
repeat 2
clap
stomp
The outer loop has three rounds. In each round, the inner loop claps twice. After that inner loop finishes, the sprite stomps once. Then the next outer round begins.
Trace one outer round per row
| Outer round | What happens |
|---|---|
| 1 | Clap, clap, stomp |
| 2 | Clap, clap, stomp |
| 3 | Clap, clap, stomp |
Count the claps as three groups of two:
That is also three times two. Adding the loop numbers would give five, but it misses a whole group. The inner loop starts again in every outer round.
The stomp runs three times. It sits inside the outer loop, after the inner loop. It does not belong to the inner loop. Six claps and three stomps make nine actions altogether.
Follow the block shapes
In a block editor, look at the two C-shaped gaps. In written code, look at the spaces before each line. The clap sits farther inward than the stomp.
Move the stomp inward beside the clap, and the inner group becomes "clap, stomp." That group runs twice per outer round. Across three outer rounds, you now get six claps and six stomps.
Decide whether nesting helps
Two outer rounds, each with three claps inside, give six claps. A single repeat 6 around clap gives the same action list. Nesting is useful when you want to show groups within groups, or do another action after each inner group. You could also write repeated actions directly inside one loop. Choose a version whose groups you can read and check.
Key Takeaways
- The inner loop finishes all its repeats on each outer round.
- For one block inside both loops, multiply the two repeat numbers.
- A block in only the outer loop runs once per outer round.
- Tracing one outer round per row keeps the groups clear.
- Moving a block into the inner loop can change its count.
3.2 Repeat whole shapes in a design
Once you have a working shape, you can make copies with an outer loop. A move or turn between copies changes where the next shape goes.
Test one shape first
Build a square loop with four equal moves and four 90-degree turns. Lower the pen before drawing. Test that it returns to its start, facing its starting direction.
Turn squares into a flower
pen down
repeat 8
repeat 4
move 50 steps
turn right 90 degrees
turn right 45 degrees
The inner loop draws one square. After it finishes, the 45-degree turn points the sprite toward the next square. This extra turn belongs inside the outer loop, after the inner loop.
The eight copies share one starting point. Their extra turns make one full turn:
The move inside the square runs four times per square. Eight groups of four give 32 moves. The 90-degree turn also runs 32 times. The extra 45-degree turn runs only eight times.
If you remove that extra turn, every square follows the same lines. You see one square drawn over eight times. If you keep the 45-degree turn but make only six copies, the extra turns total 270 degrees. The design leaves part of the full turn unfinished.
Move copies into a row
Start facing right with the pen down:
repeat 3
repeat 4
move 40 steps
turn right 90 degrees
pen up
move 60 steps
pen down
Each square returns to its own start. The sprite then travels 60 steps right without drawing. Each square is 40 steps wide, so the next square starts after a 20-step gap. The sprite also makes that pen-up move after the last square.
For copies around one point, share 360 degrees between the copies. Six copies need a 60-degree turn between them. Four squares with a 90-degree turn between copies make a window-like design.
Count the saved blocks
The flower's drawing part uses five visible blocks: two repeats, one move and two turns. The long version uses eight square instructions per copy, plus an extra turn:
Including the starting pen down gives 73 blocks for the long version and six for the nested version.
Key Takeaways
- Test the inner shape before adding an outer loop.
- Put the move or turn between copies after the inner loop.
- For evenly spaced copies around a point, divide 360 by the copy count.
- Lift the pen for a move that should leave no connecting line.
4Keep things going with forever loops
A spinning fan and a bird in a game may keep moving for a long time. You will choose whether their actions need a count or should keep repeating. Then you will combine costume changes, small moves and short waits to make an animation you can see.
4.1 Choose when the repeating should end
Some jobs have a finish. Others keep running while your program is on. Choose a loop that matches what you want to happen.
A count or no count?
| Repeat with a number | Forever |
|---|---|
| Runs a set number of rounds | Has no repeat number |
| Finishes after its last round | Keeps going until the program is stopped |
| Useful for four sides or three jumps | Useful for ongoing spinning or blinking |
A forever loop is also called an infinite loop. It repeats the inside blocks without finishing by itself. You can stop the program with its stop button.
A windmill can keep spinning with this loop:
forever
turn right 5 degrees
For exactly one full turn, use 72 repeats of that turn. The turns total 360 degrees. After its last turn, the count-controlled loop finishes.
Put starting steps first
A forever loop never reaches an ending. Blocks below it in the same script cannot start. Many block editors give it a flat bottom, so you cannot attach another block underneath.
If a fan should say "Starting!" before spinning, place that message above the forever loop. If it should spin a set number of times and then say "Finished!", use a count-controlled loop.
Using forever to draw a square keeps drawing over the same four sides. It never moves on to the next part of that script. Use four repeats when the drawing should end after one square.
Other scripts can still run
A script is a connected stack of instructions. A forever loop keeps its own stack busy. Another stack with its own start block can run at the same time. A game can keep music playing in one script while another script moves a character.
A planned forever loop is useful. It becomes a bug when endless repeating stops the program from doing the job you wanted.
Key Takeaways
- Use a number when the job needs a set number of rounds.
- Use forever for actions that keep going until you stop the program.
- A forever loop cannot finish and reach later blocks in its script.
- A separately started script can run alongside a forever loop.
4.2 Make a sprite look alive
A sprite can change pictures while it moves. Repeating those small changes can make a bird flap or a character walk.
Pictures become movement
Animation shows pictures one after another so something seems to move. A sprite's costumes are its different pictures. Give a bird one costume with wings up and another with wings down.
forever
next costume
wait 0.2 seconds
next costume switches to the next picture. After the last costume, it goes back to the first. The short wait lets you see each picture. The two bird pictures keep taking turns until you stop the program.
Wait inside the loop
A computer runs blocks very quickly. Costume changes with no pause can be too fast to follow. A wait above a loop pauses only before the animation. A wait below a fixed repeat pauses only after it. Put the wait inside so it happens after every change.
A longer wait slows the changes. A shorter wait speeds them up. Try changing only that wait and watch the difference.
Move in small steps
repeat 10
move 10 steps
wait 0.1 seconds
Ten small moves travel 100 steps altogether. The ten waits add up to one second, so the movement takes about a second. A single move 100 steps jumps there at once.
For a walking character, put a small move, next costume and a short wait inside the loop. Bigger moves cover more ground each round; smaller moves cover less. Keep the wait the same when comparing them. A built-in edge-bounce block inside the loop can make the character turn back at the screen edge.
Plan what happens
A storyboard is a few quick drawings of your animation. Sketch the start, a repeating part and an ending. Mark which pictures keep coming back.
Choose forever for a bird that flaps throughout the game. Choose a fixed repeat for a ball that rolls through ten small moves, then stops. A storyboard helps you choose the loop before you start dragging blocks.
Key Takeaways
- Costumes are different pictures of a sprite.
- A short wait inside the loop makes each costume easier to see.
- Small moves with waits show a journey over time.
- A longer wait slows an animation.
- Sketch a storyboard and choose whether the action should end.
5Predict, test and fix loops
Before you run your blocks, work out what you expect to see and hear. You will trace loops, count their actions and compare your prediction with a test. When something goes wrong, the result gives you clues. You will use those clues to make one repair at a time.
5.1 Work out the result before you run
You can read a program like a set of directions. Predicting means saying what it will do before you press start.
Trace from the top
Read any starting blocks first. Find the loop's count, or notice that it says forever. Trace the inside blocks once in order. Then count all the rounds and include any blocks after a fixed repeat.
Try this program:
say "Listen!" for 1 second
repeat 3
play bell sound
repeat 5
play woodblock sound
The loops are one after the other. The sprite says "Listen!" once, plays three bells, then plays five woodblocks. The second loop starts when the first finishes. There are eight sounds altogether.
Write every action when you need to
Unrolling makes the repeats visible. For repeat 2 around move 15 steps and say "Hello!", write:
"Move 15, say Hello!, move 15, say Hello!"
Now count two moves and two messages. The total distance traveled is 30 steps. Keep an action's place in the list; all the moves do not happen before all the messages.
For nested loops, write one outer round per row. If each row has three moves and one turn, two outer rounds give six moves and two turns. Multiply the move count by the length of each move to find the distance along the whole path.
Predict a change too
Changing a square's repeat number from four to eight keeps the move and turn the same. Eight quarter turns make two full turns. The sprite draws the same square twice. The final picture can hide the extra work.
Write a prediction before running. Then watch the actions, as well as the finished picture. If they differ from your prediction, check both the code and your counting. Either one may need fixing.
Key Takeaways
- Read the start, every loop round and the ending in order.
- Use an action list or rows to keep track of repeats.
- The final picture can hide lines drawn more than once.
5.2 Find the first thing that goes wrong
A bug makes your program do something you did not want. Debugging means finding and fixing it. Watching carefully gives you clues about which block to change.
Compare the plan and the result
First say what should happen. Run the program and describe what really happens. Look for the first point where those two stories split.
A loop meant to draw a hexagon says:
repeat 5
move 60 steps
turn right 60 degrees
It draws five sides and leaves a gap. The turn is right for a hexagon, but there should be six sides. Change only repeat 5 to repeat 6. The six turns total 360 degrees. Run it again to check that the path closes.
Match the clue to the block
| What you notice | What to check |
|---|---|
| Too many or too few actions | The repeat number |
| One long line instead of a square | Is the turn inside the loop? |
| A message appears every round | Should the message be below the loop? |
| A triangle stays open | Does the turn say 120 degrees? |
| Costume changes are too fast to see | Is a short wait inside the loop? |
| A later action never starts | Is a forever loop keeping that script busy? |
| Nothing is drawn | Is the pen down before the moves? |
| Only the first dash appears | Is pen down inside the dashed-line loop? |
Old lines can also hide your new drawing. Clear the screen at the start, then place the sprite at its starting spot and face it the starting way.
Slow the loop down
Add wait 0.5 seconds inside a loop while testing. Count rounds aloud as you watch. You may spot a turn happening once at the end when it should happen each round. Remove the extra testing wait when you have found the bug.
Test one change at a time
Change one block or number, then run again. Changing the count, turn and move all at once makes it hard to tell which change helped.
After the repair works, try another starting spot with enough room. Try a bigger shape too. Reset the start and clear old marks for each test. Check the side lengths, turns and ending, so the fix works beyond your first run.
Key Takeaways
- Compare what should happen with what actually happens.
- Find the first place where the program goes wrong.
- Use the result as a clue about the count, placement, turn, wait or pen.
- Change one thing and run again.
- Slow a loop with a testing wait when its actions are hard to follow.
- Retest with another size or starting spot.
Loops in Coding examples
1Turn a dance into a loop
12 steps
- 1IntroductionA shorter way to give directions
Imagine teaching a robot a short dance. You could list every action, or find a group that comes back again. A loop in a repeat block does that for you, so you use fewer blocks and make a change in one place.
You will mark that group, give it a repeat count and check the order. Then you will compare the robot's actions with the blocks you built.
- 2ExplanationMark the matching group
Read this dance: "reach, tap, tap, reach, tap, tap, reach, tap, tap."
The smallest matching group is "reach, tap, tap." Mark a line after each copy. There are three copies of the group, with three actions in each. The repeat count is the number of copies.
- 3ExampleKeep the opening outside
Add "wave" before that dance. The wave happens once; the group "reach, tap, tap" still happens three times.
The short directions are "wave, then repeat three times: reach, tap, tap." The opening wave belongs before the loop. It is not part of its repeating group.
- 4ChallengeFind the dance ending
The dance is "hop, nod, hop, nod, hop, nod, bow." What is the smallest repeating group, how many copies are there, and what stays after it?
---reveal---
"Hop, nod" repeats three times. The bow stays after the loop and happens once. Six counts the actions inside the groups, not the number of groups.
- 5ExplanationLook inside the C shape
A repeat block holds the instructions that run again. Its number tells you how many rounds to do.
The inside blocks run from top to bottom. After the last inside block, the loop returns to the first inside block for another round. After its last round, the script continues below it.
- 6ExampleStart before the repeats
Build this dance:
say "Watch!" for 1 second repeat 3 reach tap say "Your turn!" for 1 secondThe sprite first says "Watch!" once. That block sits above the loop, so it runs before any reach or tap. The message below is still waiting for the loop to finish.
- 7ExampleFollow the three rounds
Inside the loop, round one is "reach, tap." Round two is "reach, tap." Round three is "reach, tap."
You get three reaches and three taps. Only then does the sprite say "Your turn!" The loop repeats its whole inside group; it does not run three reaches first and then three taps.
- 8ChallengeMove the ending message
In that dance, you drag
say "Your turn!"inside the loop aftertap. How often does it run now, and when?---reveal---
It runs three times, after the tap on each round. Moving the block changed its place from a one-time ending to part of the repeated group.
- 9ExampleCount blocks, then actions
Four copies of "reach, tap" need eight visible action blocks. A repeat block with one reach and one tap inside needs three visible blocks.
You save five blocks. The robot still does eight actions when it runs. A block can run several times while appearing only once in your stack.
- 10TipMake the change once
Want every reach to become a jump? Change the reach block inside the loop. Every round now uses jump.
With copied groups, you would need to change each copy. A short comment, such as "dance steps," can remind you what a loop does. The computer ignores comments when it runs.
- 11ChallengeBuild and check a shorter dance
A long dance has "wink, clap" five times, then one bow. How many visible blocks does a loop version need? Unroll its first two rounds.
---reveal---
It needs four blocks: repeat, wink, clap and the bow below. The first two rounds are "wink, clap, wink, clap." The bow happens only after all five rounds.
- 12RecapCheck your own dance
Mark your repeating group and count its copies. Follow the inside blocks in order, then include any ending.
When you shorten a stack, unroll it to check that every action still happens where you wanted it.
2Draw a tile and build a pattern
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionGive the pen a path
- 2ExplanationGet the drawing ready
- 3ExampleDraw the first tile side
- 4ExampleFollow the next two sides
- 5ExampleClose the tile
- 6Key InsightShare the full turn
- 7ChallengeChoose the hexagon loop
- 8TipTurn outside the corner
- 9ExamplePlan one dash and gap
- 10ExampleCount the whole path
- 11ConnectionCount groups you hear or jump
- 12ChallengeRepair the dashes and count them
- 13RecapCheck the path and the marks
3Build groups inside groups
12 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionRepeat a whole small job
- 2ExplanationName the outside and inside
- 3ExampleRead one outer round
- 4ExampleFinish the second group
- 5ChallengeMove the whistle inward
- 6TipMake rows for the outer rounds
- 7ExampleBuild one triangle first
- 8ExampleTurn between triangles
- 9Key InsightKeep the two turns apart
- 10ConnectionPut copies in a row instead
- 11ChallengePlan a flower of triangles
- 12RecapFollow the jobs at each depth
4Make a lantern sprite blink
9 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionPlan the repeating pictures
- 2ExplanationChoose a count or forever
- 3Key InsightPlan the starting message
- 4ChallengeGive the blinking an ending
- 5ExampleShow each picture long enough
- 6TipChange the pause to change the speed
- 7ExampleAdd a small move each round
- 8ChallengeRepair and finish the lantern
- 9RecapSketch the animation before building
5Find the bug from the result
11 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionUse a prediction as your check
- 2ExamplePredict separate loops in order
- 3ChallengeTrace a nested path
- 4Key InsightWatch the work behind the picture
- 5ExplanationCompare two clear descriptions
- 6ExampleRepair the count
- 7ExampleRepair the place
- 8TipCheck the pen at the first missing mark
- 9ChallengeUse the first wrong result
- 10ConnectionTry the repair in another case
- 11RecapKeep a short test record
Loops in Coding practice questions
Set 1: Find and follow repeating steps10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
What does the sprite do after the greeting?
say "Hello!" for 1 second
repeat 2
hop
turn left
Show answerHide answer
Question 4 of 10
How many chime sounds does this program play?
repeat 7
play chime sound
play chime sound
play chime sound
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
This should draw one square, then say "Made it!" once. What repair makes both parts work?
pen down
repeat 4
move 35 steps
say "Made it!" for 1 second
turn right 90 degrees
Show answerHide answer
Set 2: Follow nested groups and drawing patterns10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
What is the first complete outer round of this program?
repeat 5
repeat 2
play bell sound
play click sound
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
How many claps and stamps happen?
repeat 4
repeat 5
clap
stamp
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Mia wants five 10-step dashes with 4-step gaps. Only the first dash appears. What single change fixes the dashes, and how far should the sprite travel, including the final gap?
pen down
repeat 5
move 10 steps
pen up
move 4 steps
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
What sound order does this program produce?
repeat 2
play woodblock sound
repeat 3
play bell sound
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Predict the effect of moving or changing blocks10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
How many sounds happen altogether?
play chime sound
repeat 3
repeat 4
play drum sound
play bell sound
play chime sound
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
A sprite starts on costume A and has two costumes, A then B. What costume and total travel does this program end with?
repeat 5
next costume
move 4 steps
wait 0.2 seconds
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Build, compare and repair loop designs10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Action order
Animation
B
Bug
C
Comment
Copy
Core
Costume
Count-controlled loop
D
Dashed line
Debugging
E
Efficient code
Equal groups
Expected result
F
Forever loop
Full turn
G
Gap
I
Infinite loop
Inner loop
Instruction
L
Loop
N
Nested loop
Nested repetition
O
Outer loop
P
Pen down
Pen up
Predict
Q
Quarter turn
R
Regular shape
Repeat block
Repeat count
Repeated-shape design
Repeating pattern
Repetition (iteration)
S
Script
Sequence
Skip counting
Stop button
Storyboard
T
Test
Test case
Trace
Turn amount
U
Unroll
W
Wait block
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.