Chapter 13 Structured Texts Example 2: The initial value in D0 is 1, and the initial value in D10 is 5. After the loop is terminated, the value in D0 will become 5*4*3*2*1. 13.2.5 Loop Structure - WHILE Format Description The Boolean expression is evaluated. If the value of the Boolean expression is TRUE, the sub-statement will be executed. This repeats until the value of the Boolean expression becomes FALSE. Rules and limits The Boolean expression can be a device, a symbol, or an arithmetic expression. It can not be a constant. The sub-statement will be executed if the value of the Boolean expression is TRUE, and therefore the sub-statement may not be executed.
The sub-statement can be a legal statement, or another structure. There is no limit on the number of sub-statements in a WHILE structure. One loop structure can be embedded in another loop structure. There are at most 64 loop structures. If the value of the Boolean expression following WHILE is FALSE, the loop will be terminated. To prevent an infinite loop, the operand in the Boolean expression following WHILE cannot be a device or a symbol which cannot be updated. The X devices in a program are updated after the program is scanned.
If users want to use an X device as the operand of the Boolean expression, they have to add an I/O update instruction to the structure, or update the X through an interrupt subroutine. 13-19