Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

dotimes

dotimes

type: special form (fsubr)
location: built-in
source file: xlcont.c
Common LISP compatible: yes
supported on: all machines

SYNTAX

(dotimes  ( <symbol> <end-expr> [ <result> ] ) [ <expr> ... ]  )
        <symbol>        -       a symbol
        <end-expr>      -       an integer expression 
        <result>        -       an optional expression for the returned result
        <expr>          -       expressions comprising the body of the loop
                                which may contain RETURNs, GOs or tags for GO  

DESCRIPTION

The DOTIMES special form is basically a 'for' looping construct that contains a loop <symbol>, an <end-expr> to specify the final value for <symbol>, an optional return value and a block of code (expressions) to evaluate. The sequence of execution is:

<symbol>  := 0
while  <symbol> value is not equal to <end-expr> value
        loop code execution
        <symbol>  := <symbol> + 1
end-while
return <result>

The main loop <symbol> will take on successive values from zero to (<end-expr> - 1). The DOTIMES form will go through and create and initialize the <symbol> to zero. After execution of the loop <expr>'s, the <symbol> value is incremented. This continues until the <symbol> value is equal to <end-expr>. The value of the <result> expression is evaluated and returned. If no <result> is specified, NIL is returned. When the DOTIMES is finished execution, the <symbol> that was defined will no longer exist or retain its value. If the <end-expr> is zero or less, then there will be no execution of the loop body's code.

EXAMPLES

(dotimes (i 4 "done") (princ i))        ; prints  0123   returns "done"
(dotimes (i 4)        (princ i))        ; prints  0123   returns NIL
(dotimes (i 1)        (princ i))        ; prints  0      returns NIL
(dotimes (i 0)        (princ i))        ; returns NIL
(dotimes (i -9)       (princ i))        ; returns NIL


Go to the first, previous, next, last section, table of contents.