Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Side Trips

The dog walks along a corridor between hedges. Here and there, the hedge on its left has a gap: a niche, one tile deep, with a bone in it. The niches are in different places on each map. The program from A Path with Bones won't help here: there's always a path ahead, so the dog would walk straight past the niches.

So far, each part of your If blocks held a single block. But an If can hold as many blocks as you like, and when its condition is true, it carries them all out, from top to bottom. Here, the If holds a whole little trip into the niche and back:

  1. Turn left, to face the niche.
  2. Move forward into it and pick up the bone.
  3. Turn around: two turns the same way.
  4. Move forward, back into the corridor.
  5. Turn to face the way on.

The last step is the easiest to forget. Which way does the dog face when it comes out of the niche, and which turn puts it back on its way? Put yourself in the dog's place, or turn the view.

The rest of the program is short. On every pass of the loop, the dog takes a step along the corridor and checks whether there's a niche on its left:

  • Repeat until at the goal
    • Move forward
    • If path to the left
      • the trip into the niche and back

Go through the last pass in your head: the dog steps onto the goal, and the If asks once more. There's no niche next to the goal, so nothing happens, and the loop ends.

Instructions

  1. 1

    Pick up all the bones on all the maps.

  2. 2

    Walk to the goal.

Back

8/9

  1. 1. The If Block
  2. 2. If, Else
  3. 3. Which Way at the Corner?
  4. 4. Quiz: One Part per Pass
  5. 5. An If Inside an If
  6. 6. A Path with Bones
  7. 7. Quiz: A Bug in a Nested If
  8. 8. Side Trips
  9. 9. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.