XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

dotimes


Type:   -   special form (fsubr)
Source:   -   xlcont.c

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
returns - the return value of the result expression or NIL

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 'exprs', 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

See the dotimes special form in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next