Parker Hannifin
Example
The following demonstrates a simple
GOTO
statement. The program
sets output bit 32, then moves axis X one incremental unit in the
positive direction. The program pauses until the “Not in Position“ bit
768 is clear, then clears the output, waits 2 seconds, and goes to
LOOP1.
ACC10 DEC10 STP10 VEL1
_LOOP1
SET 32
X/1
INH -768
CLR 32
DWL 2
GOTO LOOP1
Repetition
The repetition structure—known as a loop—controls the repeated
execution of a statement or block of statements.
While the conditions remain true, the program loops (or iterates)
through the specific code. Typically, the repetition structure includes
a variable that changes with each iteration. And a test of the value
determines when the conditions of the expression are satisfied. The
program then moves to the next statement past the repletion
structure.
If the condition is not met, the loop does not execute. In many cases
that is acceptable behavior. Conversely, if the condition is always
met, then the loop does not end. An endless loop is probably not a
desired result, so be mindful when writing the loop conditions.
AcroBASIC also provides the following looping statements:
•
FOR/TO/STEP/NEXT
•
WHILE/WEND
FOR/TO/STEP/NEXT
When you expect to loop through a block of code for a number of
times, the
FOR/NEXT
loop is a good choice. It contains a counter, to
which you assign starting and ending values. You also assign a
STEP
value (positive direction only), the value by which the counter
increments.
When the
FOR/NEXT
loop executes the first time, the end value and
the counter are compared. If the current value is past the end
value, the
FOR/NEXT
loop ends and the statement immediately
following executes. Otherwise, the statement block within the
FOR/NEXT
loop executes.
On each encounter of the
NEXT
statement, the counter increments
and loops back to the
FOR
statement. The counter is compared to
the end value with each loop. When the counter exceeds the end
value, the loop skips the statement within, and proceeds to execute
the statement immediately following the
FOR/NEXT
statement.
22 Programmer’s Guide