Clojure: Flow Control (if then else)

By Xah Lee. Date: . Last updated: .

The form for if statement is:

(if test body)

If you want a “else” part, the form is

(if test true_body false_body)

Use a (do ) to group the bodies.

if returns the value of the evaluated branch.

Example:

(if (< 3 2) 9 ) ;  nil
(if (< 3 2) "yes" "no" ) ;  "no"
(if nil 3 4 )  ;  4

there is also