🔁 Loops & Conditionals | Betabox

🔁 Loops & Conditionals

Loops

This week, we’ve already used some loops. See if you can remember what these blocks do:

These allow us to repeat the same action as many times as we like.

Yesterday, we used a repeat block to make our character move smoothly across the stage.

Here are some other ways we can use loops:

  • Create a clone of a sprite every 1 second
  • Always have a sprite moving towards your mouse
  • Can you think of any more?

Conditionals

Conditionals sound a bit scary, but I promise they’re really easy!

Conditionals are usually just “if-then statements” that allow us to do one thing if something is happening, and another thing if it’s not happening.

  • In real life, an example of this might be a stoplight. If the light is green, you can go through, else you must stop your car.
  • In the hedgehog game we saw before, we want the score to go up by one point if the hedgehog touches the cheese puffs; else we want the cheese puffs to keep moving around.
  • In our stories, maybe we want to show a different background if a user clicks a certain sprite; else the background will stay the same.
  • Try to come up with a few more “if-then statements” from games you play or from your daily life.