ACR Electronics FPR-10 PROGRAMMER Manual Página 54

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
Vista de página 53
Parker Hannifin
54 Programmer’s Guide
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.
You can exit a FOR/NEXT loop before the counter is complete using
a BREAK statement. When the condition is met, the statement
immediately following the FOR/NEXT loop executes.
Example
The following demonstrates a FOR/NEXT loop with a BREAK
statement.
FOR LV0 = 0 TO 499 STEP 1
PRINT LA0(LV0), SA0(LV0)
DWL 0.01
IF (BIT 24)
BREAK
ENDIF
NEXT
Vista de página 53
1 2 ... 49 50 51 52 53 54 55 56 57 58 59 ... 198 199

Comentários a estes Manuais

Sem comentários