GNU Info

Info Node: (elisp)Control Structures

(elisp)Control Structures


Next: Variables Prev: Evaluation Up: Top
Enter node , (file) or (file)node

Control Structures
******************

   A Lisp program consists of expressions or "forms" (Note: Forms).
We control the order of execution of these forms by enclosing them in
"control structures".  Control structures are special forms which
control when, whether, or how many times to execute the forms they
contain.

   The simplest order of execution is sequential execution: first form
A, then form B, and so on.  This is what happens when you write several
forms in succession in the body of a function, or at top level in a
file of Lisp code--the forms are executed in the order written.  We
call this "textual order".  For example, if a function body consists of
two forms A and B, evaluation of the function evaluates first A and
then B.  The result of evaluating B becomes the value of the function.

   Explicit control structures make possible an order of execution other
than sequential.

   Emacs Lisp provides several kinds of control structure, including
other varieties of sequencing, conditionals, iteration, and (controlled)
jumps--all discussed below.  The built-in control structures are
special forms since their subforms are not necessarily evaluated or not
evaluated sequentially.  You can use macros to define your own control
structure constructs (Note: Macros).

Sequencing
Evaluation in textual order.
Conditionals
`if', `cond', `when', `unless'.
Combining Conditions
`and', `or', `not'.
Iteration
`while' loops.
Nonlocal Exits
Jumping out of a sequence.

automatically generated by info2www version 1.2.2.9