Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / downward loop

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. downward loop
#1209
Posted by: guidance 2002-10-06 15:06:05
How can I get a loop downward, i.e.:
DO i=10 TO 0
 ...
END
It doesn't work in Reginald, loop is not executed at all.

I know in C:
FOR (i=10;i>=0;i--) ... ;
or in BASIC:
FOR i=10 TO 0 step -1
 ...
next
How can I do it in REXX?
Message2. Re: downward loop
#1211
Posted by: 2002-10-07 05:41:10
Add the BY keyword to the end of your DO statement, and specify by how much you want to decrement the loop variable on each iteration. For example, if you want "i" to start at 20 and decrement by 1 each time you loop until it gets to 0, then add BY -1 as so:
DO i=10 TO 0 BY -1
   SAY i
END
Note that this will execute the loop at total of 11 times (because it also gets executed when i = 0).

This is discussed in my Rexx Book under the heading "Loops -> Repeat a set number of times": http://www.borg.com/~jglatt/rexx/scripts/language/iterate.htm
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0