EXIT statement is used to terminate an entire loop unconditionally and immediately. As soon as the EXIT statement is executed, the loop is terminated and the statements following the loop are processed.
The syntax for exit statement is −
Note − If the EXIT statement is used in a nested loop, only the current loop is executed after the EXIT statement is processed.
Report YH_SEP_15. DO 5 TIMES. IF SY-INDEX = 3. EXIT. ENDIF. Write / SY-INDEX. ENDDO.
The above code produces the following output −