Summary -

In this topic, we described about the below sections -

In some cases, a block of statements needs to be executed repeatedly. Looping statements(While, Do loop, Nested Do/While loop) are used to support the above scenario.

A loop statement is to execute a statement or set of statements repeatedly. The looping iterations can be performed until the specified condition in the loop statement is false.

The block of statements gets executed repeatedly until the condition is determined as false. The condition may be single or combination of multiple conditions.

Loop statements should have at least one condition. Condition can be either a combination of two operands with relational operator in between or one operand, value with relational operator in between.

Below diagram decribes the flow of simple Looping statement -

Loop Statements Flow Diagram

In the above flow, if the specified condition is determined as true, then the statements-set1 executed and control again validates the specified condition. The statements-set1 gets executed until the condition is false. If the condition specified is determined as false, then the control transfers to statements-set2 directly.

ABAP programming language supports the below list of loop statements -

WHILE Loop Executes statement or set of statements repeatedly until the condition is false.
Condition get executed at the begining of the loop.
The statements in the loop wont execute even the condition is false for the first time.
DO Loop Executes statement or set of statements repeatedly until no of times specified.
Do loop is an unconditional loop.
Nested One or more loop statements in another loop statement.
While/DO loop can be nested.