6 Application Instructions API 00-49 Explanations: 1. No operand. No contact to drive the instruction is required. 2. FOR instruction indicates FOR ~ NEXT loops executing back and forth N times before escaping for the next execution. 3. N = K1 ~ K32,767. N is regarded as K1 when N ≤ 1. 4. When FOR~NEXT loops are not executed, the user can use the CJ instruction to escape the loops. 5. Error will occur when a) NEXT instruction is before FOR instruction. b) FOR instruction exists but NEXT instruction does not exist. c) There is NEXT instruction after FEND or END instruction. d) The number of instructions between FOR ~ NEXT differs. 6. FOR~NEXT loops can be nested for maximum five levels.
Be careful that if there are too many loops, the increased PLC scan time may cause timeout of watchdog timer and error. Users can use WDT instruction to modify this problem. Program Example 1: After program A has been executed for 3 times, it will resume its execution after NEXT instruction. Program B will be executed for 4 times whenever program A is executed once. Therefore, program B will be executed 3 Ч 4 = 12 times in total. NEXT A B NEXT DVP-PLC Application Manual 6-18 API Mnemonic Function 09 NEXT End of a FOR-NEXT Loop OP Descriptions Program Steps N/A NEXT:
1 steps PULSE 16-bit 32-bit SA SX SC EH SV EH3 SV2 EH3 ES EX SS SA SX SC EH SV EH3 SV2 ES EX SS ES EX SS SA SX SC EH SV SV2 FOR K3 FOR K4