Skip to content
Related Articles
Open in App
Not now

Related Articles

When Construct in LISP

Improve Article
Save Article
  • Last Updated : 09 Nov, 2021
Improve Article
Save Article

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,

  1. condition is a test statement used to test
  2. statements are the actions that will depend on the condition

Example 1: LISP Program to check the number is equal to 50 or not

Lisp




;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

Lisp




;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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!