RTC6 boards
Doc. Rev. 1.0.21 en-US
6 Developing RTC6-User Programs
122
6.5.5 Loops
Although list jumps, see Chapter 6.5.3 ”Jumps”,
page 120, and conditional jumps, see Chapter 9.3.2
”Conditional Command Execution”, page 295, let
you repeat any number of list commands limitlessly
or under external control, precisely specifying the
number of executions is not always reliably possible.
But this can be achieved by the command pair
list_repeat and list_until. The command sequence
between these two short list commands execute
exactly as often as specified with the list_until
command’s parameter, but at least once. Here,
nesting up to 8 loops deep is allowed.
list_repeat and list_until must always be used in
pairs. Unpaired or supernumerous commands
(list_until without an associated list_repeat, as well
as list_repeat commands leading to a nesting depth
greater than 8) are ignored. Empty loops (for
example, list_repeat directly followed by list_until)
terminate immediately and are not repeated.
The command pairs can be located both within lists
and within subroutines.
Within subroutines, list_until performs a
list_jump_rel to the address directly after the
associated list_repeat. Loops do not function
beyond the boundaries of a subroutine, because list
jumps into or out of subroutines are not allowed, see
Chapter 6.5.3 ”Jumps”, page 120.
Within lists, however, list_until executes a
list_jump_pos (to the address directly after the
associated list_repeat). Thus, list_repeat and
list_until can even reside in two different lists,
provided that list changing is ensured (by either an
explicit list jump or an automatic list change).
If, on the other hand, a list actually has been
terminated (as may be the case when using
auto_change_pos), then the list_repeat stack gets
automatically deleted and the started loop can no
longer be ended because the next list_until no longer
finds an associated list_repeat.
set_end_of_list deletes the entire loop
management, if no automatic list change is pending,
but list_return does not.
Explicit list jumps into or out of the body of a
list_repeat/list_until loop are allowed because they
cannot be monitored. Careless use could therefore
compromise loop management integrity so severely
that started loops do not execute as expected (but
subroutine calls from inside a loop are always reliably
possible as long as the subroutine itself contains no
unpaired list
_repeat/list_until
commands).
If a list_repeat/list_until loop is to be executed with
an initially unknown number of repetitions, a high
value (for example, greater than the highest expected
number) can be specified for the
Number
parameter of
list_until. Within the loop, a conditional branch (for
example, which is dependent on an external signal)
can jump to a position outside the loop and leave the
loop this way. At this point there should be a
list_until(
Number
= 0 ) to end the just left loop
properly.