Loops with CodeSparks

Some of the puzzles in lesson 1 are actually quite difficult. If your child needs more time to complete them please feel free to work on them again this week. I’ve updated lesson 1 with a link to the solutions for parents to help guide their student and also new connection codes.

This week I am unlocking chapter 2 of the puzzles which explores the concept of loops or repeating patterns. Make no mistake these are initially quite difficult concepts for preps, but I am always amazed at how quickly they pick it up. Don’t worry if they don’t get it straight away – some of my year 6 students still haven’t quite understood it yet. There’s plenty of time!

If students can work through the first 8 puzzles they are doing very well. Set a time limit of about 30 minutes – then they should take a break.

Help our construction Foo find his tools.

Go into the puzzles area of the app and this time clock on the play button in ‘Tool Trouble’ as pictured above. The first puzzle doesn’t require the use of loops, but it sets the story. Our friend needs to use a new block to build boxes so he can reach his tool floating high above him (see below).

Build 3 boxes so Woz can reach his missing wrench.

Each box tells Woz to build a box so in effect we are repeating the same command 3 times. This is how simple loops work – rather than have 3 separate commands (e.g. build a box, build a box, build a box) we use a loop that effectively says: build 3 boxes! We’ll see the use of a loop in the next puzzle.

What is that strange new thing?

This puzzle is incomplete, but it shows how I’ve used the new loop block. The number represents the number of times that the instructions inside will be repeated. So this ‘code’ effectively says: build a box 3 times. Woz still needs to jump to the right to get his saw after he builds the boxes, but I thought I’d leave that out. You might also notice that when you ‘run’ the code the animation is a lot faster than the first puzzle. This has been done on purpose as code that uses loops is a lot more efficient for a computer to run.

As you advance through these puzzles you should receive new blocks that make things more interesting. I’m going to skip to puzzle 6 now to demonstrate 2 new ideas:

  • The forever (infinite) loop
  • Multiple blocks inside a loop
Let’s call it a forever loop instead of ‘infinite’ even though that’s the correct term.

In this puzzle, Woz is faced with several challenges. He must somehow make his way through 2 crates and 8 tyres to get to his screw driver and collect the gem. Thankfully he has the explosive power of TNT, but the biggest problem is that tyres are unpredictable. Dynamite is also unpredictable. How many explosions will it take to clear the boxes? Probably just 1. How about the tyres? It’s difficult if not impossible to predict. In these scenarios it’s best to use the ‘forever loop’ which just keeps repeating the code inside ‘until’ the objective is reached. So it’s not really a forever loop, but technically it could go on forever if the tyres kept blocking the way.

You will see in my suggested solution that I also have 2 blocks inside the forever loop. The first explodes the dynamite and the 2nd jumps to the right. You need both as Woz needs to keep trying to get to his tool and we don’t really know how many repetitions are required. You can have many blocks inside the loop and you can also have blocks before and after the loop. You can also have many loops.

Here’s a link to the solutions for chapter 2 in case you need help:

I have also recorded an introductory video for students where I go through the first few puzzles. It’s about 10 minutes long.

Please excuse my homely fashion – it’s cold!

As always you can contact me on my school email address: gong@standrews.vic.edu.au if you have any questions.

1 Comment

Submit a Comment

Your email address will not be published.