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

While There's a Path Ahead

The dog walks up and turns right at the corner. But the corner is somewhere else on every map, and Repeat until at the goal won't help: the dog would keep walking straight and step off the path at the corner. It has to tell where the path ends.

That's why the dog has senses. The path ahead block looks at the tile in front of the dog and answers yes or no. A question whose answer is yes or no is called a condition. Instead of yes and no, programmers say true and false.

Conditions are hexagonal and do nothing by themselves. They go into the hexagonal slot of other blocks, for example the new Repeat while … loop. It works like Repeat until at the goal, just with a condition of your choice:

  • Repeat while path ahead
    • Move forward

Before every pass, the dog looks ahead. As long as there's a path there, it takes a step. As soon as there's no path ahead, the loop ends and the program goes on. So the dog stops exactly at the corner, wherever it is.

Instructions

  1. 1

    Get the dog to the goal on all three maps: go up to the corner, turn right and walk to the goal.

Back

3/8

  1. 1. Repeat Until at the Goal
  2. 2. Stairs of Any Height
  3. 3. While There's a Path Ahead
  4. 4. Corner After Corner
  5. 5. Quiz: Only What's Ahead
  6. 6. Bones All the Way
  7. 7. An Endless Loop
  8. 8. Summary
Next

Try it yourself

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