# Difference between Case, Cond and Condp

Case compares the value with each condition with `=`

and evaluates the expression in the matched branch.

`(defn case-test-1`

[n]

(case n

1 "n is 1"

2 "n is 2"

"n is other"))

# Cond

When you want to do a similar thing to `case`

but want to write your own test case rather than =, you can use `cond`

. You can write a different test case in each branch with `cond`

.

`user=> (defn cond-test`

[n]

(cond

(= n 1) "n is 1"

(and (> n 3) (< n 10)) "n is over 3 and under 10"

:else "n is other"))

# Condp

You can use a predicate with `condp`

for condition. In this case `contains?`

is the predicate.

user=> (defn condp-test-2

[n]

(condp contains? n

#{1 2 3} "n is either 1 or 2 or 3"

"n is not 1 or 2 or 3"))

#'user/condp-test-2user=> (println (condp-test-2 2))

n is either 1 or 2 or 3

niluser=> (println (condp-test-2 5))

n is not 1 or 2 or 3

nil

You can use a predicate with `condp`

for condition. In this case, `contains?`

is the predicate.