• Subject: Re: FOR loop available in RPG IV
  • From: boldt@xxxxxxxxxx
  • Date: Tue, 7 Nov 2000 13:53:10 -0500
  • Importance: Normal

Bill wrote:
>Oh, that's nice.  So to use the FOR you have to test C>A or C<A and select
>the FOR instance that you want to run.  Interesting that the format
>I changed my test code and it works fine for any input now.  Nice way to
>confuse my fellow coders.

When in doubt, look it up in the RPG Reference Manual.
contains the relevant information on the FOR statement.

According to the Reference, the initialization, increment, and limit
clauses are all optional.  Furthermore, if both are specified, the
increment and the limit clause may be in either order.

If initialization clause is omitted, the index is not initialized.
If the increment clause is omitted, it defaults to "by 1";
If the limit clause is omitted, the index keeps incrementing on
each iteration and it's the programmers responsibility to exit the
loop somehow, using some opcode like LEAVE, RETURN, or LEAVESR.

Also note, the increment and limit expressions are evaluated each
time through the loop, and so the behavior of the loop can change

Thus, the following FOR statements are all valid:

        for i = 1 to 10 by 3

        for i = 1 by incr to number*incr

        for i = 10 downto 1

        for i = 1

        for i to 10

        for i by 3

        for i

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com

| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com

This thread ...

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].