If Construct in LISP

• Last Updated : 09 Nov, 2021

In this article, we will discuss the if construct in LISP. The if is a decision-making statement used to check whether the condition is right or wrong. The if the condition is right, then it will go inside the if block and execute the statements under if block. Otherwise, the statements are not executed.

Syntax:

(if (condition) then (statement 1).....(statement  n))

Here, then is an optional keyword used inside the if statement.

Example 1: LISP Program to check conditions with operators

Lisp

 ;define value to 100(setq val1 100)  ;check the number is equal to 100(if (= val1 100)   (format t "equal to 100"))     (terpri)  ;check the number is greater than to 50(if (> val1 50)   (format t "greater than 50"))    (terpri)  ;check the number is less than to 150(if (< val1 150)   (format t "less than 150"))

Output:

equal to 100
greater than 50
less than 150

Example 2:

Lisp

 ;define value to 230(setq val1 230)  ;check the number is equal to 100(if (= val1 100)   (format t "equal to 100"))     (terpri)  ;check the number is greater than to 50(if (> val1 50)   (format t "greater than 50"))    (terpri)  ;check the number is less than to 150(if (< val1 250)   (format t "less than 250"))

Output:

greater than 50
less than 250

My Personal Notes arrow_drop_up