We're at v4r3m0. I just tried putting a 'for' opcode in an RPGLE program. Got an error: Operation entry is not valid; specification is ignored.
>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
>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.
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
Hans Boldt, ILE RPG Development, IBM Toronto Lab, email@example.com
This mailing list archive is Copyright 1997-2019 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