1<?xml version="1.0" encoding="ISO-8859-1"?>
2<html><head><title>Loops</title><meta name="generator" content="DocBook XSL Stylesheets V1.40"/></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="section"><a name="dsssl.expr.loop"/><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="dsssl.expr.loop"/>Loops</h2></div><hr/></div><p>
3<a class="indexterm" name="id2790042"/>
4<a class="indexterm" name="id2790059"/>
5<a class="indexterm" name="id2790077"/>
6
7DSSSL doesn't have any construct that resembles the
8for loop that occurs in most imperative languages like C
9and Java. Instead, DSSSL employs a common trick in
10functional languages for implementing a loop: tail recursion.
11</p><p>
12Loops in DSSSL use a special form of
13<tt>let</tt>. This loop counts from 1 to 10:
14<pre class="screen">
15(let <a name="dl1"/><img src="/images/callouts/1.png" alt="1" border="0"/>loopvar <a name="dl2"/><img src="/images/callouts/2.png" alt="2" border="0"/>((count 1))
16  <a name="dl3"/><img src="/images/callouts/3.png" alt="3" border="0"/>(if (&gt; count 10)
17    <a name="dl4"/><img src="/images/callouts/4.png" alt="4" border="0"/>#t
18    (<a name="dl5"/><img src="/images/callouts/5.png" alt="5" border="0"/>loopvar <a name="dl6"/><img src="/images/callouts/6.png" alt="6" border="0"/>(+ count 1))))</pre></p><div class="calloutlist"><a name="id2790240"/><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a name="id2790250"/><a href="#dl1"><img src="/images/callouts/1.png" alt="1" border="0"/></a> </td><td valign="top" align="left"><p>This variable controls the loop. It is declared without an
19initial value, immediately after the <tt>let</tt>
20operand.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="id2790316"/><a href="#dl2"><img src="/images/callouts/2.png" alt="2" border="0"/></a> </td><td valign="top" align="left"><p>
21<a class="indexterm" name="id2790341"/>
22
23Any number of additional local variables can be defined after
24the loop variable, just as they can in any other
25<tt>let</tt> expression.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="id2790390"/><a href="#dl3"><img src="/images/callouts/3.png" alt="3" border="0"/></a> </td><td valign="top" align="left"><p>If you ever want the loop to end, you have to put some sort of a
26test in it.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="id2790222"/><a href="#dl4"><img src="/images/callouts/4.png" alt="4" border="0"/></a> </td><td valign="top" align="left"><p>This is the value that will be returned.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="id2791018"/><a href="#dl5"><img src="/images/callouts/5.png" alt="5" border="0"/></a> </td><td valign="top" align="left"><p>Note that you iterate the loop by using the loop variable as if
27it was a function name.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="id2791053"/><a href="#dl6"><img src="/images/callouts/6.png" alt="6" border="0"/></a> </td><td valign="top" align="left"><p>The arguments to this function are the values that
28you want the local variables declared in <a href="#dl2" title=""><img src="/images/callouts/2.png" alt="2" border="0"/></a> to have
29in the next iteration.</p></td></tr></table></div></div></body></html>
30