Article View: comp.lang.modula2
Article #821Re: Why are the loops so awkward?
From: Klaus Moeller
Date: Thu, 14 Jun 1990 16:22
Date: Thu, 14 Jun 1990 16:22
39 lines
2154 bytes
2154 bytes
ccc_ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes: >This is an unwarranted generalisation. Consider the following example >(it should be pretty much self-explanatory): > LOOP > IF NrCharsLeft = 0 THEN > StringsSame := TRUE; > EXIT > END (*IF*); > INC(SourceIndex); > DEC(NrCharsLeft); > IF String1[SourceIndex] <> String2[SourceIndex] THEN > StringsSame := FALSE; > EXIT > END (*IF*) > END (*LOOP*) >Do you think you could write it just as simply and clearly using something >other than LOOP? I don't think so. Do you think this is an unusual example? >I find that, in my programs, the majority of my loops are best written >using LOOP-with-EXIT rather than WHILE, REPEAT or FOR. Of course no. But this was meant for loops with only one exit. You must use LOOP for loops that have more than one exit point simply because you can't do that with FOR, WHILE or REPEAT. But when you have only one exit point, WHILE, FOR and REPEAT are much clearer. In C you can have while and for loops with additional exits in them, Modula prohibits this. I suppose that Wirth wanted to isolate this in pure LOOPs. The Semantics of while, repeat and for become much easier this way. Klaus -- /---------------------------------------------------------------------\ / Klaus Moeller, Leiteweg 2, 2940 Wilhelmshaven, West - Germany \ | UUCP : moeller at uniol.uucp | BITNET : 078326 at DOLUNI1.BITNET | |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| \ Fill what's empty, empty what's full and scratch where it itches / \---------------------------------------------------------------------/
Technical Details
Message-ID:
<2813@uniol.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!unido!uniol!moellerReferences:
<5377.26731960@puddle.fidonet.org> <728.26767558@waikato.ac.nz> <22213@boulder.Colorado.EDU> <747.2677cd57@waikato.ac.nz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!unido!uniol!moeller From: moeller@uniol.UUCP (Klaus Moeller) Newsgroups: comp.lang.modula2 Subject: Re: Why are the loops so awkward? Message-ID: <2813@uniol.UUCP> Date: 14 Jun 90 16:22:58 GMT References: <5377.26731960@puddle.fidonet.org> <728.26767558@waikato.ac.nz> <22213@boulder.Colorado.EDU> <747.2677cd57@waikato.ac.nz> Organization: University of Oldenburg, W-Germany Lines: 39