REBOL Document

Repeat - Function Summary


Summary:

Evaluates a block a number of times or over a series.

Usage:

repeat word value body

Arguments:

word - Word to set each time (must be: word)

value - Maximum number or series to traverse (must be: integer series)

body - Block to evaluate each time (must be: block)

Description:

If the value is an integer, the word is used to keep track of the current loop count, which begins at one and continues up to and including the integer value given. If the value is a series, then the word holds the first value of each element of the series (see FOREACH). Returns the value of the final evaluation. The BREAK function can be used to stop the loop at any time (but no value is returned). The word is local to the block.


    repeat num 5 [print num]
    1
    2
    3
    4
    5

Related:

for - Repeats a block over a range of values.
forall - Evaluates a block for every value in a series.
foreach - Evaluates a block for each value(s) in a series.
forskip - Evaluates a block for periodic values in a series.
loop - Evaluates a block a specified number of times.
until - Evaluates a block until it is TRUE.
while - While a condition block is TRUE, evaluates another block.

User Comments:

-From: lmecir_mbox.vol.cz 2-Dec-2000/4:05:28-8:00:

Warning: Repeat modifies its Body argument. If you need to reuse the Body (in the case of recursive functions, e.g.), use it in combination with Copy/deep as in:


    repeat word value copy/deep body

-From: allen_rebolforces.com 15-Dec-2000/21:44:25-8:00:

REPEAT operates faster than FOR, so use REPEAT in place of FOR wherever you can.


<Back | Index | Next>

Copyright 2004 REBOL Technologies