XLISP while

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# while

Type: | - | Lisp macro (closure)
Source: | - | misc.lsp

## Syntax

(while condition body)
  condition - test expression for terminating the 'while' loop
  body - Lisp expressions to be executed inside the loop
  returns - returns NIL or a value defined by (return expr) inside body

In Nyquist, 'while' is implemented as a Lisp macro:

    (defmacro while (condition &rest body)
      `(prog () loop (if ,condition () (return)) ,@body (go loop)))

## Description

The 'while' macro implements a conventional 'while' loop. If the 'condition' evaluates to true, the expressions in the in the 'body' are evaluated, then the 'condition' is tested again. If the 'condition' evaluates to false, the 'while' loop terminates. The 'while' macro returns NIL unless a (return expr) is evaluated in the 'body', in which case the value of 'expr' is returned.

## Examples

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference