📜  Rexx-循环

📅  最后修改于: 2020-11-02 03:59:05             🧑  作者: Mango


到目前为止,我们已经看到了依次执行的语句。另外,在Rexx中提供了语句来更改程序逻辑中的控制流。然后将它们分类为控制声明流,我们将对其进行详细研究。

循环语句使我们可以多次执行一个语句或一组语句。下图是大多数编程语言中循环语句的一般形式。

循环

让我们讨论一下Rexx支持的各种循环。

Sr.No. Loop Type & Description
1 do loop

The do loop is used to execute a number of statements for a certain number of times. The number of times that the statement needs to be executed is determined by the value passed to the do loop.

2 do-while loop

The do-while statement is used to simulate the simple while loop which is present in other programming languages.

3 do-until loop

The do-until loop is a slight variation of the do while loop. This loop varies in the fact that is exits when the condition being evaluated is false.

受控重复

可以执行do循环以执行受控的语句重复。

句法

这种陈述的一般语法如下。

do index = start [to limit] [by increment] [for count] 
statement #1 
statement #2 
end 

该语句的不同之处在于,存在一个用于控制循环执行次数的索引。其次,有一些参数说明索引应该从哪个值开始,应该在哪里结束以及增量值是多少。

流程图

我们来看看这个循环的流程图-

受控重复

从上图可以清楚地看到,循环是根据索引值以及索引值如何递增执行的。

以下程序是受控重复语句的示例。

/* Main program */ 
do i = 0 to 5 by 2 
   say "hello" 
end 

在上述程序中,计数i的值首先设置为0。然后以2为单位递增,直到该值不大于5。

上面的代码输出将是-

hello 
hello 
hello