Making Choices -- Conditional Execution

What things can Karel find out about in his world?

Karel can evaluate test functions that tell him whether something about his world is true or false.

How can Karel make choices?

Karel can decide to do one thing or another based on whether a test is true or false. For example to make sure Karel doesn't try to pick up a beeper when none is available: BEGINNING-OF-PROGRAM BEGINNING-OF-EXECUTION IF next-to-a-beeper THEN pickbeeper ELSE move END turnoff END-OF-EXECUTION END-OF-PROGRAM The IF is followed by a test function. The THEN and ELSE are followed by instructions. The END shows where this instruction stops.

You can leave out the ELSE part if it's not necessary or place no instructions between THEN and ELSE or ELSE and END.

Repeating Instructions


This document is copyright 1994 by Joseph N. Wilson.
$Id$