summaryrefslogtreecommitdiff
path: root/devdocs/elisp/control-structures.html
blob: 286bb2f5d53dfc3f98b975923525918da0971943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 <h2 class="chapter">Control Structures</h2>    <p>A Lisp program consists of a set of <em>expressions</em>, or <em>forms</em> (see <a href="forms">Forms</a>). We control the order of execution of these forms by enclosing them in <em>control structures</em>. Control structures are special forms which control when, whether, or how many times to execute the forms they contain. </p>  <p>The simplest order of execution is sequential execution: first form <var>a</var>, then form <var>b</var>, 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 <em>textual order</em>. For example, if a function body consists of two forms <var>a</var> and <var>b</var>, evaluation of the function evaluates first <var>a</var> and then <var>b</var>. The result of evaluating <var>b</var> becomes the value of the function. </p> <p>Explicit control structures make possible an order of execution other than sequential. </p> <p>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 (see <a href="macros">Macros</a>). </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="sequencing" accesskey="1">Sequencing</a>
</td>
<td> </td>
<td align="left" valign="top">Evaluation in textual order. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="conditionals" accesskey="2">Conditionals</a>
</td>
<td> </td>
<td align="left" valign="top">
<code>if</code>, <code>cond</code>, <code>when</code>, <code>unless</code>. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="combining-conditions" accesskey="3">Combining Conditions</a>
</td>
<td> </td>
<td align="left" valign="top">
<code>and</code>, <code>or</code>, <code>not</code>, and friends. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="pattern_002dmatching-conditional" accesskey="4">Pattern-Matching Conditional</a>
</td>
<td> </td>
<td align="left" valign="top">How to use <code>pcase</code> and friends. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="iteration" accesskey="5">Iteration</a>
</td>
<td> </td>
<td align="left" valign="top">
<code>while</code> loops. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="generators" accesskey="6">Generators</a>
</td>
<td> </td>
<td align="left" valign="top">Generic sequences and coroutines. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="nonlocal-exits" accesskey="7">Nonlocal Exits</a>
</td>
<td> </td>
<td align="left" valign="top">Jumping out of a sequence. </td>
</tr> </table><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Control-Structures.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Control-Structures.html</a>
  </p>
</div>