Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!K.GP.CS.CMU.EDU!jgm From: jgm@K.GP.CS.CMU.EDU (John Myers) Newsgroups: comp.lang.misc Subject: For loops (was: Re: From Modula to Oberon) Message-ID: <1103@PT.CS.CMU.EDU> Date: 11 Mar 88 18:41:22 GMT References: <7161@sol.ARPA> <2787@enea.se> <1345@daimi.UUCP> <1301@eneevax.UUCP> Sender: netnews@PT.CS.CMU.EDU Organization: System/Technology Development Corp. Lines: 27 Keywords: FOR In article <1301@eneevax.UUCP> noise@eneevax.umd.edu.UUCP (Johnson Noise) writes: >In article <1345@daimi.UUCP> erja@daimi.UUCP (Erik Jacobsen) writes: > >>This problem does not exist with WHILE/REPEAT-loops, and removing >>the FOR-loop from a language is one effective way of making it >>cleaner. > > I guess I don't have to tell you how C handles the problem. >In my opinion, it is by far, the most logical. The for construct I know about which is by far the most logical (though is also the hardest to implement efficiently) is the one provided by CLU. In short, CLU has this construct called an "iterator", which is similar to a procedure, but instead of returning a single set of values, "yields" a sequence of sets of values. Each set is are assigned in turn to the loop variables of a for statement and the body of the for statement is executed. ----- BTW: In C, one of my favorite standard macros is: #define _forlist(var,init,next) for((var)=(init);var;(var)=(var)->next) -- John G. Myers John.Myers@k.gp.cs.cmu.edu