🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1689

Re: Need Help With 'BY'

#1689
From: josef Moellers
Date: Mon, 07 Jan 1991 08:27
63 lines
2103 bytes
In <91003.102704BJ020000@NDSUVM1.BITNET> BJ020000@NDSUVM1.BITNET (Dave Mueller) writes:


>I'm trying to write a FOR loop that needs a 'nonconstant' BY, for example:

>IF Case = 1 THEN
>   Begin := 0;
>   End := Length(Line)-1;
>   By := 1;
>ELSE
>   Begin := Length(Line)-1;
>   End := 0;
>   By := -1;
>END;

>FOR Loop := Begin TO End BY By DO
>etc..


>Any suggestions as to how I go about doing this in a FOR Loop???  Or am I gonna
>end up doing it some other way??

My version of PIM (3rd corrected ed.) states:

(Page 158, "Report on The Programming Language Modula-2":)
9.8 For Statements
... Its [the variable's] value should not be changed by the statement
sequence.
... C [the increment/decrement] must be a constant of type INTEGER or
CARDINAL.

(Page 172, "Appendix 1, The Syntax of Modula-2":)
ForStatement = FOR ident ":=" expression TO expression
	[BY ConstExpression] DO StatementSequence END.
	    ^^^^^

So, Your pretty much out of luck. I see two possibilities:
1 You make it two FOR-statements with an IF-statement selecting between
  both (You could put it into the CASE)
2 Use a WHILE-statement:

	replace

  FOR Loop := Begin TO End BY By DO

	by

  Loop := Begin;
  WHILE Loop <= End DO
     <statements>
     INC(Loop, By);
  END;

>Thanx much!

>Dave Mueller

Josef Moellers
--
| Josef Moellers		| c/o Siemens Nixdorf Informationssysteme AG |
|  USA: mollers.pad@nixdorf.com	| Abt. STO-XS 113			     |
| !USA: mollers.pad@nixdorf.de	| Heinz-Nixdorf-Ring			     |
| Phone: (+49) 5251 104662	| D-4790 Paderborn			     |
Technical Details
Message-ID: <josef.663236830@ugum01>
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!linus!nixbur!nixpbe!ugun13!ugum01!josef
References: <91003.102704BJ020000@NDSUVM1.BITNET>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!linus!nixbur!nixpbe!ugun13!ugum01!josef
From: josef@nixpbe.nixdorf.de (josef Moellers)
Newsgroups: comp.lang.modula2
Subject: Re: Need Help With 'BY'
Message-ID: <josef.663236830@ugum01>
Date: 7 Jan 91 08:27:10 GMT
References: <91003.102704BJ020000@NDSUVM1.BITNET>
Sender: news@ugun13.UUCP
Lines: 63