× 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.



James,

I see what you're saying with your two examples. So what's really more
similar is that both leave the variable i as 1 greater than it was last
processed within the loop (if that makes sense). So while i may = 10
after the first loop finishes, the loop only processed i from 0 to 9. I
think this is the commonality Simon was really trying to get at (correct
me if I'm wrong Simon, I don't want to put words in your mouth).

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of James Rich
Sent: Monday, February 02, 2009 3:45 PM
To: RPG programming on the IBM i / System i
Subject: Re: FOR loop limit

On Tue, 3 Feb 2009, Simon Coulter wrote:

generally 0-based. However, in all programming languages (at least
that I can think of), on for-loop termination, the index of the loop
is always 1 greater than the terminal value--regardless of the
starting value.

Not necessarily true, depending on how you think of "termination value".

In many languages, a common construct for for loops is the following:

for (i=0; i<10; i++)

In this case the loop terminates when i reaches a value of ten, i.e.
equal
to the termination value. Contrast the above to this:

for (i=1; i<=10; i++)

The above construct is common in RPG using the DO and FOR opcodes. In
this case i does reach a value which is one greater than the termination

value of ten.

Of course none of the above matters either way if you are coding a for
loop using an index that cannot fit the test required. If you use an
index that is 4,0 and your test is i < 10000 then it will never work
because you're index cannot ever get to your termination value of 10000.

The case is similar for i <= 9999. In my opinion, the first way of
coding
(i.e. the "C way") is more clear that your index needs to be large
enough
to reach the termination value. I think seeing "10000" makes the size
requirement jump off the page more than "9999".

James Rich

if you want to understand why that is, there are many good books on
the design of operating systems. please pass them along to redmond
when you're done reading them :)
- Paul Davis on ardour-dev

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.