For function

Syntax

For count = expression1 To expression2 [Step i]
   statement_list
End-For

Description

Use the For loop to cause the statements of the statement_list to be repeated until count is equal to expression2. Step specifies the value by which count will be incremented for each iteration of the loop. If you do not include Step, count is incremented by 1 (or -1 if the start value is greater than the end value.) Any statement types are allowed in the loop, including other loops.

Note:

If your index variable in a For loop is an integer, explicitly declare the variable as integer to greatly improve runtime performance.

A Break statement inside the loop causes execution to continue with whatever follows the loop. If the Break occurs in a nested loop, the Break does not apply to the outside loop.

Example

The following example loops through all of the rows for the FIELDNAME scroll area:

&FIELD_CNT = ActiveRowCount(DBFIELD_VW.FIELDNAME);

Local integer &i;
For &i = 1 To &FIELD_CNT;
   WinMessage(MsgGetText(21000, 1, "Present Row Number is: %1", &i));
End-For;