× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • 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
changes!
>FOR,BY,TO but FOR,DOWNTO,BY.
>
>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.
<http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AGZ03/4.4.43>
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
dynamically.

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
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.