Delta ISPSoft — 13.2.6 Loop Structure - FOR

Chapter 13 Structured Texts  Description The initial value of the symbol or the initial value in the device is the start value. Whenever the loop body is executed, the value of the symbol or the value in the device increases by the increment. If the value of the symbol or the value in the device is in the range of the start value to the end value, the loop body will be executed. If the value of the symbol or the value in the device is not in the range of the start value to the end value, the loop will be terminated.  Rules and limits  The start value/end value/increment can be a device, a symbol, an arithmetic expression, or a constant.

The data type of the start value/end value/increment must be INT (-32768~32767) or DINT (-2147483648~2147483647). If a device is used as the start value/end value/increment, the system will automatically regard the value in the device as an integer. Besides, if an arithmetic expression is used as the start value/end value/increment, and the result of the operation is not an integer, the result will be rounded down to the nearest whole digit.  If the end value is less than the start value, the increment must be a negative number. Otherwise, there will be an infinite loop.  The data type of the symbol must be INT or DINT.

If the symbol or the device takes part in the operation, please prevent the value of the symbol or the value in the device from resulting in an infinite loop.  The sub-statement can be a legal statement, or another structure. There is no limit on the number of sub-statements in a FOR structure. One loop structure can be embedded in another loop structure. There are at most 64 loop structures.  After the value of the symbol or the value in the device increases by the increment, the system will check whether the value of the symbol or the value in the device is in the range of the start value to the end value.

If an overflow occurs after the value of the symbol or the value in the device increases by the increment, there will be an infinite loop.  Example The initial value of the symbol INDEX is 1. Whenever the loop body is executed, the value of INDEX increases by 2. After the loop body is executed for the fifth time, the value of INDEX will increase by 2, and the value of INDEX will become 11. Owing to the fact that the value INDEX is not in the range of 1 to 9, the loop is terminated. The initial value of the symbol SU is 0. After the loop is terminated, the value of SU will become 1 2 +3 2 +5 2 +7 2 +9 2 . 13-21