Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loop control

14 views
Skip to first unread message

robin....@gmail.com

unread,
May 1, 2012, 10:41:25 PM5/1/12
to
On Monday, 16 April 2012 00:50:03 UTC+10, glen herrmannsfeldt wrote:
> ana......@hotmail.com <ana......@hotmail.com> wrote:
>
> (snip)
> > subroutine test
> > if (0< huge(0)) print *, ' zero less than huge(0)'
> > do j = 0,huge(0)
> > if (j > 10) stop
> > print *, j
> > enddo
> > stop
> > end
>
> > zero less than huge(0)
> > Program Completed
> > Press Enter to Continue.
>
> > In other words, If I try to run the loop from 0 to huge(0) it never
> > enters the loop.
>
> As far as I know, that is allowed.
>
> The loop count, huge(0)-0+1, doesn't fit in the appropriate sized
> variable.

In PL/I, that would be detected as an integer overflow error at run-time.

Moreover, PL/I provides the means to deal with loops that terminate
at some hardware upper limit, without overflowing:

DO I = 0 UPTHRU 2147483647;

Such a loop is handled differently from the conventional one where "TO" is used:
DO I = 0 TO 2147483647;
which would overflow (with run-time error) for the reason that after the
final iteration the traditional way is to perform one more increment of the
control variable "I".

[assuming a 32-bit word in both cases]
0 new messages