🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4198

Re: types of the limit expressions of FOR statements

#4198
From: Matthew Eric Seitz
Date: Sun, 17 Apr 1988 04:00
34 lines
1849 bytes
In article <5035@nsc.nsc.com> woolsey@nsc.UUCP (Jeff Woolsey) writes:
>While we're on the subject of FOR statements and limits, fill in the
>blank below with something that will make the loop execute 26 times.
>
>MODULE Poser;
>
>FROM somewhere IMPORT something;
>
>VAR 
>  ch: CHAR;
>
>BEGIN
>  FOR ch := 'Z' TO 'A' BY _____ DO
>    something(ch)
>  END
>END Poser.

	I'm not even sure that the index variable can be of type CHAR.  The
definition of FOR on p. 158 of _Programming_In_Modula-2_, it seems to imply
that the index for a FOR statement must of type INTEGER or CARDINAL.  This
is because it defines the value of the index in terms of the "+" operator,
which applies only to operands of type INTEGER, CARDINAL, or REAL, and of
the step value, which must be of type INTEGER or CARDINAL ( "A, A+C,
A+2C" ). 

	On the other hand, on p. 162 Wirth defines INC( x, n ) as x := x + n,
but then adds that if x is of type CHAR or an enumeration type x is replaced
by the n-th successor of x.  Under this interpretation, and assuming that if
n < 0 x is replaced by the ABS(n) predecessor of x, you should be able to
fill the blank with -1.  Similarly, you can interpret a step value < 0 as
equivalent to DEC( x, n ) with the same results.

					Matthew Seitz
					seitz@cory.berkeley.edu
Technical Details
Message-ID: <2457@pasteur.Berkeley.Edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!ucbvax!pasteur!cory.Berkeley.EDU!seitz
References: <INFO-M2%88041418081804@DB0TUI11> <5035@nsc.nsc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!ucbvax!pasteur!cory.Berkeley.EDU!seitz
From: seitz@cory.Berkeley.EDU (Matthew Eric Seitz)
Newsgroups: comp.lang.modula2
Subject: Re: types of the limit expressions of FOR statements
Message-ID: <2457@pasteur.Berkeley.Edu>
Date: 17 Apr 88 04:00:31 GMT
References: <INFO-M2%88041418081804@DB0TUI11> <5035@nsc.nsc.com>
Sender: news@pasteur.Berkeley.Edu
Reply-To: seitz@cory.Berkeley.EDU.UUCP (Matthew Eric Seitz)
Organization: University of California, Berkeley
Lines: 34