In this article, we will discuss the when construct. The when is a decision-making statement used to specify the decisions. It is similar to conditional statements.
Syntax:
(when (condition) (statements) )
where,
- condition is a test statement used to test
- statements are the actions that will depend on the condition
Example 1: LISP Program to check the number is equal to 50 or not
;set number to 50
(setq number 50)
;condition check the given number is equal to 50
(when (= number 50)
;statement
(format t "Equal to 50")
)
Output:
Equal to 50
Example 2: LISP Program to check the given number with comparison operators
;set number to 50
(setq number 50)
;condition check the given number is equal to 50
(when (= number 50)
;statement
(format t "Equal to 50")
)
(terpri)
;set number to 150
(setq number 150)
;condition check the given number is greater than or equal to 50
(when (>= number 50)
;statement
(format t "greater than or Equal to 50")
)
(terpri)
;set number to 10
(setq number 10)
;condition check the given number is less than or equal to 50
(when (<= number 50)
;statement
(format t "less than or Equal to 50")
)
Output:
Equal to 50 greater than or Equal to 50 less than or Equal to 50