10.4.2.10. FOR~NEXT
10.4.2.10. FOR~NEXT
Explanation | As long as variable is equal to or less than ending value, the variable value is increased, and bloc is repeatedly executed. | |
Grammar | FOR <variable>=<init.value> TO <end value> [STEP <increment >] ~ NEXT | |
Parameter | Variable | Arithmetic variable. This variable determines whether to repeat the execution. |
init.value | Arithmetic variable. A value for initial setup. | |
End value | Arithmetic variable. When the variable is equal to or less than this ending value, bloc is repeatedly executed. When there is no interval or is positive, it is repeated only when the variable value is smaller than the end value. When the internal is negative, it is repeated only when the variable value is equal to or higher than the end value. | |
increment | Arithmetic variable. Increase amount value to increase the variable value. | |
Example | ‘Slowly moving to R1 shift direction. FOR V1!=300 TO 0 STEP -33.3 P1=P1+R1 MOVE L,P1,S=V1!mm/sec,A=3,T=1 UNTIL DI1 NEXT |
※ Caution
l If the command exits from or to the command block of GOSUB~RETURN, IF~ENDIF and FOR~NEXT command for Hi4 and Hi4a controller, the task execution can malfunction or cause『E1245 Block stack exceeded』error.
l Hi5 controller does not have this restriction. But, if you execute the CALL command too many times without an END command, or if you have too many GOSUB without any RETURN, you must be careful because it can cause a『E1245 Block stack exceeded』error.