SAP ABAP While循环

2018-12-29 16:24 更新
只要给定条件为真,WHILE循环语句就会重复执行目标语句。

WHILE命令的一般格式如下 :

WHILE <logical expression>  

<statement block>. 
    
ENDWHILE.

语句块可以是单个语句或语句块。
WHILE循环执行由WHILE和ENDWHILE命令包围的语句,直到逻辑表达式变为false。

流程图

SAP ABAP While循环

在考虑程序的性能时,WHILE命令是优选的。 循环继续,直到发现逻辑语句是不真实的,并且如果找到false语句,则退出循环,并且执行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

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号