if

In Clojure, the most basic tool we have for the flow control is the if operator. It allows you to choose between two options depending upon a condition.

 
(def condition true)
โ€‹
(if condition
  (str "evaluate first expression if true")
  (str "evaluate second expression if false"))
โ€‹x
 
the evaluation will appear here (soon)...

Reference: Conditional if

If your age is less than the legal drinking age, then you can only be served water or soda.

If your age is greater, then you have a wider set of drinks available.

 
(def age 24)
(def legal-drinking-age 21)
โ€‹
(if (< age legal-drinking-age)
  ["water" "soda"]
  ["water" "soda" "beer" "wine"])
 
the evaluation will appear here (soon)...

results matching ""

    No results matching ""