Hu oh! Your buggle got lost again in the same kind of maze, but this time,
the corridors are not always of the same size. Since there is no way to know
the length of the corridor before taking it, a for
will not
suffice anymore. Instead, you will have to change your inner loop to use a
while
loop, using the method crossing()
that tells
whether your buggle currently stands on an intersection.
The extra complexity is that at the beginning of a corridor, you obviously
stand on an intersection, but you still want to move on. [!java|scala|c]For
that, the easiest is to use a do / while
loop instead of a
regular while
loop to move until the next intersection.[/!]
[!python]For that, use an extra variable indicating whether you already
entered the corridor, as follows. This will ensure that you execute the loop
body at least once (when firstTime
is true) before we actually
use the value returned by crossing()
to determine to continue
or not.[/!]
firstTime = True while firstTime or not crossing(): firstTime = False (loop body)[/!]
With that new trick, your buggle should exit this maze quite easily.