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



Scott Klement wrote:

But to the question at hand, which is, does "DO *HIVAL" loop an
indeterminate number of times? Well, technically, yes. At least, if you
compile using TRUNCNBR(*YES), which is the default. By default, decimal
arithmetic on fixed-form calcs (but not the expression calcs) truncates
on overflow. That means that when the implicit loop index reaches the
value of *HIVAL, rather than overflowing when it's incremented again, it
gets truncated. Thus, the implicit loop index never exceeds the limit,
and the loop keeps churning away. (At least until the operator notices
and cancels the job!)


Wow... that's obscure.   I can't believe people would write code like
this!  I mean, if we didn't have the ability to get answers from the
compiler team, how would I have EVER known that "DO *HIVAL" was going to
loop infinitely?

It sure isn't obvious.


You may well have run into this issue in another guise. For example, how many times does the DO loop iterate in the following program?


C     1             do        9             x                 1 0
C     x             dsply                   a                 1
C                   enddo
C                   seton                                        lr

9 times? Uh-uh. Since the loop index X can never exceed the maximum value for that variable, the loop never ends.

If this hasn't bitten you, it has almost certainly caught some readers of this list off guard. It's yet another reason to compile with TRUNCNBR(*NO). Or to always use integer or unsigned variables for loop indexes, and not decimal.

Cheers! Hans



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.