for

Define a counter-based processing loop.

for  Counter = StartValue to EndValue
    {step StepValue}
    Your ProcScript
endfor

Parameters

Parameters
Parameter Data Type Description
Counter Number Current value of the counter
StartValue Number Initial value of the counter
EndValue Number End value of the counter
StepValue Number Step size by which the counter is incremented (or decremented); if not specified, the default value is 1.

Return Values

None

Use

Allowed in all component types.

Description

The for statement defines a counter-based processing loop, which initializes Counter with the StartValue and repeatedly executes the code in the block until one of the following conditions is met:

  • StepValue>= 0 and Counter>EndValue
  • StepValue< 0 and Counter<EndValue
  • A break statement is encountered

After the loop completes (after the endfor statement), the Counter holds the value it had when the loop ended.

The Counter, EndValue and StepValue can be altered by the code in the loop, which enables you to conditionally make changes in the loop as it executes.

Note:  If the EndValue is not specified, the loop runs forever, so it must be broken by a break.

In the following example, the counter (vCounter) is decreased by 2 each time the for loop is executed. A break statement stops the loop after it has executed 6 times.

variables
   numeric vCounter
   numeric vLoops
endvariables

vLoops = 0
for vCounter = 100 to 0 step -2
    vLoops += 1	
    putmess "Counter: %%vCounter, Loop count: %%vLoops "
    if (vLoops >= 6) 
	   putmess "Loop processing stopped" 
       break
    endif
endfor

The resulting output looks like this:

Counter: 100, Loop count: 1
Counter: 98, Loop count: 2
Counter: 96, Loop count: 3
Counter: 94, Loop count: 4
Counter: 92, Loop count: 5
Counter: 90, Loop count: 6
Loop processing stopped
History
Version Change
9.5.01 Introduced

Related Topics