Chapter 4. Ladder Diagram (LD) Programming112 PACSystems* RX7i, RX3i and RSTi-EP CPU Programmer's Reference Manual GFK-2950C4.5.4 For LoopA FOR loop repeats rung logic a specified number of timeswhile varying the value of the INDEX variable in the loop.A FOR loop begins with a FOR_LOOP instruction and endswith an END_FOR instruction.The logic to be repeated must be placed between the FORand END_FOR instructions.The optional EXIT_FOR instruction enables you to exit the loopif a condition is met before the FOR loop ends normally.When FOR_LOOP receives power flow, it saves the START, END, and INC (Increment) operands anduses them to evaluate the number of times the rungs between the FOR_LOOP and its END_FORinstructions are executed. Changing the START and END operands while the FOR loop is executingdoes not affect its operation.When an END_FOR receives power flow, the FOR loop is terminated and power flow jumps directlyto the statement following the END_FOR instruction.There can be nothing after the FOR_LOOP instruction in the rung and the FOR_LOOP instructionmust be the last instruction to be executed in the rung. An EXIT_FOR statement can be placed onlybetween a FOR instruction and an END_FOR instruction. The END_FOR statement must be the onlyinstruction in its rung.A FOR_LOOP can assign decreasing values to its index variable by setting the increment to anegative number. For example, if the START value is 21, the END value is 1, and the increment valueis –5, the statements of the FOR loop are executed five times, and the index variable is decrementedby 5 in each pass. The values of the index variable will be 21, 16, 11, 6, and 1.When the START and END values are set equal, the statements of the FOR loop are executed onlyonce.When START cannot be incremented or decremented to reach the END, the statements within theFOR loop are not executed. For example, if the value of START is 10, the value of END is 5, and theINCREMENT is 1, power flow jumps directly from the FOR statement to the statement after theEND_FOR statement.Note: If the FOR_LOOP instruction has power flow when it is first tested, the rungs between theFOR and its corresponding END_FOR statement are executed the number of times initiallyspecified by START, END, and INCREMENT. This repeated execution occurs on a single sweepof the PLC and may cause the watchdog timer to expire if the loop is long.Nesting of FOR loops is allowed, but it is restricted to five FOR/END_FOR pairs. Each FOR instructionmust have a matching END_FOR statement following it.Nesting with JUMPs and MCRs is allowed, provided that they are properly nested. MCRs andENDMCRs must be completely within or completely outside the scope of a FOR_LOOP/END_FORpair. JUMPs and LABEL instructions must also be completely within or completely outside the scopeof a FOR_LOOP/END_FOR pair. Jumping into or out of the scope of a FOR/END_FOR is not allowed.