Download DI-159 PLC Manual - DATAQ Instruments
Transcript
DI-159 PLC Hardware Manual StickOS Looping Conditional Statements Looping conditional statements include the traditional BASIC for-next loop and the more structured while-endwhile and do-until loops. The for-next loop statements are of the form: for variable = expression to expression step expression statements next Where statements is one or more program statements and the step expression clause is optional and defaults to 1. The for-next loop expressions are evaluated only once, on initial entry to the loop. The loop variable is initially set to the value of the first expression. Each time the loop variable is within the range (inclusive) of the first and second expression, the statements within the loop execute. At the end of the loop, if the incremented loop variable would still be within the range (inclusive) of the first and second expression, the loop variable is incremented by the step value, and the loop repeats again. On exit from the loop, the loop variable is equal to the value it had during the last iteration of the loop. The while-endwhile loop statements are of the form: while expression statements endwhile do Where statements is one or more program statements . Alternately, the string form of this statement is: while string relation string do statements endwhile The while-endwhile loop conditional expression is evaluated on each entry to the loop. If it is true (non-0), the statements within the loop execute, and the loop repeats again. On exit from the loop, the conditional expression is false. The do-until loop statements are of the form: do statements 52