IF Statement

Programs often need to take different actions depending on the data. The if statement allows this:

(if test thenform )
(if test thenform elseform )

The test is evaluated first. If it returns a value that is considered true ( anything other than #f), the thenform is evaluated and its value is the value of the if. If the value of the test is #f, the elseform is evaluated and its value is the value of the if.


   (define (abs x)
     (if (< x 0)
         (- x)
         x ) )

Note that the thenform and elseform are single forms; if multiple things need to be done, they must be enclosed in a begin.

Contents    Page-10    Prev    Next    Page+10    Index