LISP – Loop Construct

  • Post author:
  • Post category:LISP
  • Post comments:2 Comments
LISP - Loop Construct

This topic is about LISP – Loop Construct.

The loop construct is the simplest form of iteration provided by LISP. In its simplest form It allows you to execute some statement(s) repeatedly until it finds a return statement.

It has the following syntax −

(loop (s-expressions))

Example

Create a new source code file named main.lisp and type the following code in it.

(setq a 10)
(loop 
   (setq a (+ a 1))
   (write a)
   (terpri)
   (when (> a 17) (return a))
)

When you execute the code, it returns the following result −

11
12
13
14
15
16
17
18

Please note that without the return statement, the loop macro would produce an infinite loop.

To know more, Click Here.

This Post Has 2 Comments

  1. amb superslot

    Thank you for your article.Thanks Again. Awesome.

Leave a Reply