$loop variable is set at the start of every iteration (and
at the non-
BREAK end) of looping statements, e.g.
TIMPORT, etc. Inside the loop, it is the iteration
count (counting from 0); at the end of the loop, it is thus the number
of iterations. In version 8.00.1645136290 20220217 and later,
$loop is also set at the end of self-closing optional-looping
statements, just as if the statement was looping.
Note that for
$loop also includes the
SKIP value; this is not true for other looping
statements. Note also that for
is set before the
WHILE condition is evaluated, so that
$loop may be used as a iterator in the condition.
Note that in version 8 and later syntax (
$ret.code variable is
often a more reliable way of checking success/failure of a
<sql> statement than checking
$loop, as the latter can
be 0 for a zero-result-row successful statement as well as a failed
(no rows matched) statement.