<LOOP [SKIP=s] [MAX=m] [REV] $var1 ...>
... statements ...
LOOP statement iterates through the values of the given
variables, executing the given statements each time. Inside the
LOOP, any reference to a
LOOP variable returns the
current value of the variable, instead of the first (0th) value: in the
nth loop iteration, the nth value of each variable is used. The
loop continues until the last value of the variable with the most
values is iterated, or
MAX iterations have occurred.
is optional; its argument is an integer literal or variable.
SKIP is given, then the first s values of the variables
are skipped; i.e. iteration (and the value of
unlike with other looping statements) starts with the sth value
instead of the 0th.
LOOP, the special variable
$loop is set at
the start of each iteration to the current loop count (i.e. the
current array index). When the
set to the number of iterations (plus however many values were
SKIPped). This provides an easy way to enumerate or count
values inside the
$next is set to the "next" loop value each
iteration. Inside the loop, this is
$loop + 1: an easy way to
count values starting from 1 instead of 0. When the
$next is equal to
$loop: it is the value to
SKIP in a new
LOOP to continue iteration at the
REV flag is given, then the variables are iterated
in reverse order, from last to first values. However the values
$next are still incremented forwards.
BREAK statement is encountered inside the loop, the
LOOP is exited at that point, as if none of the variables had
any further values. The
however, will have whatever values they had inside the loop.
The single-value nature of iterated variables applies globally. If
a function is called from within a
LOOP, references to the
LOOP's variables (if global) still return just the
single current value. Variables not listed in the current
tag, however, still return all their values inside a
LOOP variable inside the loop will only change
the current value of the variable; see
Variable Assignment (here). This can happen not
only with an explicit variable assignment, but indirectly if a
function or statement is called that sets
$ret, for example.
$ret is generally not advised,
as nearly any function called inside the loop will attempt to
$ret - possibly losing type information and/or
values. This is also true of other statements in Vortex that
put variables in a loop, such as
SQL. Use the
setting [Texis] Warn Ret Loop or the
command-line option (here) to
warn when such code is compiled.
This example generates radio buttons for a list of colors (essentially the
<$colors = Red Orange Yellow Green Blue Violet>
<$rgb = FF0000 FFA500 FFFF00 00FF00 0000FF EE82EE>
<LOOP $colors $rgb>
<input type="radio" name="rgb" value="$rgb"/> $colors
REV flag was added in version 3.0.947100000 20000105.
LOOPs can be nested; however the same
should not be used in an inner
LOOP since it is already a
The values of "short"
LOOP variables, i.e. ones with fewer
values than others in the same
LOOP, appear as empty when
iterated past their end.