Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!asuvax!ncar!boulder!wolniewi From: wolniewi@boulder.Colorado.EDU (WOLNIEWICZ RICHARD HANSON) Newsgroups: comp.lang.modula2 Subject: Re: Why are the loops so awkward? Message-ID: <22213@boulder.Colorado.EDU> Date: 13 Jun 90 16:23:18 GMT References: <5377.26731960@puddle.fidonet.org> <728.26767558@waikato.ac.nz> Sender: news@boulder.Colorado.EDU Reply-To: wolniewi@tramp.Colorado.EDU (WOLNIEWICZ RICHARD HANSON) Organization: University of Colorado, boulder Lines: 36 In article <728.26767558@waikato.ac.nz> ccc_ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes: >There are two interpretations of this situation: > >1) Unless they're a natural fit to the problem you're trying to solve, > stay away from zero-based arrays. Only C programmers could love them. But look at what Modula 2 _requires_ us to use when we pass an array into a procedure. >2) FOR-loops also have their problems. So who needs FOR, WHILE and > REPEAT loops, anyway? Use a LOOP statement with one or more EXITs instead. Using FOR, WHILE, and REPEAT loops would usually seem to be preferable to LOOP statements with EXITs, for a number of reasons: 1) They more clearly express the intent of the programmer, and thus make the program easier to understand in the future. 2) Avoiding EXITs makes it easier (or trivial) to determine under what conditions the loop will terminate, making post-condition verification much easier. 3) Since FOR, WHILE, and REPEAT provide more semantic information, a compiler may be able to perform more optimization that in a LOOP construct. For example a compiler could check the constraints on the looping variable's range in a FOR loop at compile time, whereas using INC inside of the loop might require the code to check the constraints at run time, and on every iteration. Usage of looping constructs can be a very religious issue, of course. This is just my best understanding of the issues involved. . . ______ Laboratory for Atmpospheric and Space Physics | / \ (__ ._) University of Colorado, Boulder |__/ \____) | Richard Wolniewicz (wolniewi@tramp.colorado.edu) Disclaimer: Only the opinions of a grad student (me)