Topic: DMD0079

FOR - Index Loop


The Index Loop (FOR) instruction begins a For/Next loop in which the rungs ladder logic instructions between the For instruction and the Next instruction will be executed a predefined number of times. For/Next loops can be nested, and there is no practical limit to how deep the nesting can go.

 

Note: All of the looping instructions are 'power-rail' instructions. Even though the instructions are displayed in the left-most column of the ladder diagram (the power rail), they are created in the right-most column of the ladder logic diagram (the output column). Creating these instructions in Do-more Designer is a bit counter-intuitive because the first step is to position the edit cursor in the output column of the ladder logic diagram (the far right; in most cases, on the NOP instruction) instead of positioning it against the power rail (the far left).

 

Note: The looping instructions are unconditional so they will run any time the code-block in which they reside is enabled. The preferred method for making them conditional is to place the loop in a Task code-block and use the Enable Task (ENTASK) instruction to run the loop whenever required.

 

Parameters:

Note: Use the F9 key (Element Browser) or Down-Arrow key (Auto-Complete) at any time to see a complete list of the memory locations that are valid in the current field of the instruction.

 

Index - designates a memory location used by the For/Next loop to count loop iterations. The Index is incremented by the By Step value each iteration of the loop. This value can be any writable numeric location.

 

From - designates the beginning count for the For/Next loop. This value can be any integer constant, or any readable numeric location.

 

To - designates the ending count for the For/Next loop. The logic within the loop will execute until the Index value is equal to this value. The For/Next loop will end only when the Index value exceeds the To value.  This value can be any integer constant, or any readable numeric location.

 

By Step - will increment or decrement the counter by the value that is specified. Specify a positive By Step value if the For/Next loop is counting up, or a negative By Step value if the For/Next loop is counting down. This value can be any positive or negative integer constant except 0, or any readable numeric location.

 


Status Display:

The FOR instruction will show the current .TimeSlice value of the Program or Task when status is ON.

 


See Also:

 


Rung Example:

The following simple example uses V100 as the loop index. It will be initialized to 4000 (From) on the first pass through the loop, and will increment by 1 (By Step) on each successive pass until it gets to 4009 (To).

 

If there were values in D4000-4009, this example will compare each of them to the value in D4010 (which was set to 0 on Rung 1). Each time a value larger than what is in D4010, the value in D4010 will be replaced with this larger value. The end result is the largest value in the range D4000-4009 will be loaded to D4010.