The cond Expression
When if statements are nested more than
one or two levels, it is often clearer to
use Racket's cond expression:
(cond (test1 action1)
(test2 action2)
.
.
(testn actionn)
(else actionn+1))
This has the same meaning as the nested if from before:
cond details:
- The tests are evaluated in order until
one results in true
- If testj is true, then actionj is
evaluated and no other action is taken
- The last test may be the keyword else