ABAP - Keyword Documentation →  ABAP - Reference →  Program Flow Logic →  Iteration Expressions →  FOR - Iteration Expressions → 

FOR - Conditional Iteration

Syntax

... FOR var = rhs [THEN expr] UNTIL|WHILE log_exp [let_exp] ...

Effect

This syntax form of an iteration expression executes a conditional iteration.

The parameters and arguments of the iteration expression must be specified as follows:

The variables declared in FOR expressions are local. The local data from all outer FOR expressions can be used when their values are defined. The iteration variable and helper variables can be used after the FOR expression, either in additional subexpressions or to construct the result.

The system field sy-index is not set by a FOR expression.

Notes

Example

The example generates a string from the numbers 0 to 9.

cl_demo_output=>display(
  REDUCE string( INIT s = ``
                 FOR  i = 1 UNTIL i > 10
                 NEXT s = s && |{ i - 1 }| ) ).

Executable Examples

Examples of Iteration Expressions