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

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

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/4