在ABAP中退出循环(Exit, Continue, Check) 用法

本文介绍了在ABAP中如何使用EXIT, CHECK和CONTINUE来控制循环流程。EXIT用于永久退出循环,程序执行在循环后的语句;CHECK在循环内若条件不满足则终止当前循环迭代,继续下一次;CONTINUE则立即结束当前循环并开始下一次循环。这些语句为ABAP程序员提供了灵活的循环控制手段。
摘要由CSDN通过智能技术生成

1Introduction

In the blog I will introduce how to exit loop. It is used in the abap.

2 Usage

2.1.Exit

If the EXIT statement is listed within a loop, it leaves the loop by ending the current loop process. Program execution is continued after the closing statement in the loop.


DATA limit TYPE i VALUE 10.
DO.
  IF sy-index > limit.
    EXIT.
  ENDIF.
  WRITE / sy-index.
ENDDO.

2.2.Check

If the statement CHECK is executed in a loop and log_exp is incorrect, the statement CHECK immediately terminates the current loop pass and the program continues with the next loop pass. For log_exp, you can specify any logical expression.

DATA remainder TYPE i. 
DO 20 TIMES. 
  remainder = sy-index MOD 2. 
  CHECK remainder = 0. 
  WRITE / sy-index. 
ENDDO.
2.3. continue

The CONTINUE statement can only be used in loops. If it is used, the current loop pass is ended immediately and the program flow is continued with the next loop pass.

DATA remainder TYPE i.
DO 20 TIMES.
  remainder = sy-index MOD 2.
  IF remainder <> 0.
     CONTINUE.
  ENDIF.
  WRITE / sy-index.
ENDDO.

3. Summary

EXIT terminate loop for ever and continue programe after the statement of loop.
CONTINUE and CHECK are only terminate current loop and go on next loop.

CHECK log_exp.
Effect

If the statement CHECK is executed outside a loop and log_exp is incorrect, the statement terminates the current process block. You can specify any logical expression for log_exp

data limit type i value '10'.

    check limit  is initial.

  write / limit.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值