Clojure - Decision Making


Advertisements

Decision-making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Sr.No. Methods & Description
1 If Statement

In Clojure, the condition is an expression which evaluates it to be either true or false. 'If' the condition is true, then statement#1 will be executed, else statement#2 will be executed.

2 If/do Expression

The ‘if-do’ expression in Clojure is used to allow multiple expressions to be executed for each branch of the ‘if’ statement.

3 Nested If Statement

Multiple 'if' statements embedded inside each other.

4 Case Statement

Clojure offers the ‘case’ statement which is similar to the ‘switch’ statement available in the Java programming language.

5 Cond Statement

Clojure offers another evaluation statement called the ‘cond’ statement. This statement takes a set of test/expression pairs.

Advertisements