SAP ABAP - WHILE循环



WHILE 循环语句会重复执行目标语句,直到给定条件为真。

WHILE 命令的通用格式如下:

WHILE <logical expression>  

<statement block>. 
    
ENDWHILE.

语句块可以是单个语句或语句块。

WHILE 循环执行 WHILE 和 ENDWHILE 命令包含的语句,直到逻辑表达式变为假。

流程图

While Loop

在考虑程序性能时,WHILE 命令是首选。循环将持续进行,直到发现逻辑语句为假,如果发现假语句,则退出循环,并执行 WHILE 循环后的第一个语句。

示例

REPORT YS_SEP_15.
  
DATA: a type i. 
 
a = 0.
  
WHILE a <> 8.
  
   Write: / 'This is the line:', a.  
   a = a + 1.
   
ENDWHILE.

以上代码产生以下输出:

This is the line: 0 
This is the line: 1 
This is the line: 2 
This is the line: 3 
This is the line: 4 
This is the line: 5 
This is the line: 6 
This is the line: 7
sap_abap_loop_control.htm
广告

© . All rights reserved.