- Name:
-
loop
- Syntax:
-
DO
{code}
LOOP
DO WHILE/UNTIL condition
{code}
LOOP
DO
{code}
LOOP WHILE/UNTIL condition
Condition - The condition which will cause the associated code commands to be executed or not.
Code - Command statements which will be executed dependant upon the evaluation of the condition.
- Description:
-
Indicates the end of a do..loop block, a section of code that will execute continuously, or while or until a condition is met.
Conditions
The condition determine whether the code will be executed or not. Each condition takes the form -
|
variable comparison value |
|
The variable's value is compared with the value to determine if the condition is met. For example -
DO WHILE pinC.1 = 0 TOGGLE B.7 LOOP
|
or |
|
|
variable comparison variable |
|
The left variable's value is compared with the right variable's value to determine if the condition is met. For example -
DO WHILE b0 < b1 TOGGLE B.7 b0 = b0 + 1 LOOP
|
The comparison operator may be any of ...
|
= |
equal to |
|
is |
equal to |
|
<> |
not equal to |
|
!= |
not equal to |
|
> |
greater than |
|
< |
less than |
|
>= |
greater than or equal to
|
|
<= |
less than or equal to
|
Note that when testing an input pin, the 'pin' variable name must be used and not the pin number or the pin's port.number label. For example -
|
DO WHILE pin2 = 1
|
|
LOOP UNTIL pinC.0 = 0
|
If the 'pin' variable name is not specified a 'syntax error' will likely be raised for the 'do' or 'loop' command. Care needs to be taken when specifying an input pin to test using the symbol command.
Multiple conditions
Multiple conditions may be specified in a 'do' or 'loop' conditional command. These can either be 'and' or 'or' combinations -
|
condition AND condition |
|
condition OR condition |
An 'and' combined condition will only evaluate as true when both conditions are true while an 'or' combined condition will evalauate as true when either condition is true.
It is possible to add addditional 'and' or 'or' combinations but it is recommended not to mix both in a combined conditional. For example -
|
DO WHILE pin2 = 1 AND pin4 = 1
|
|
LOOP UNTIL b0 = 2 OR b3 > b4
|
DO
{code}
LOOP
The code within the do...loop will be continually executed. An exit command can be used to exit out of the do...loop, execution will continue after the 'loop' command.
DO WHILE condition {code} LOOP |
|
DO UNTIL condition {code} LOOP |
The code within the do...loop will execute while (or until) the specfied condition is met. An exit command can be used to exit out of the do...loop, execution will immediately continue after the 'loop' command.
DO {code} LOOP WHILE condition |
|
DO {code} LOOP UNTIL condition |
The code within the do...loop will execute at least once and continule to execute while (or until) the specfied condition is met. An exit command can be used to exit out of the do...loop, execution will immediately continue after the 'loop' command.