Path: utzoo!mnetor!uunet!husc6!bloom-beacon!athena.mit.edu!peter From: peter@athena.mit.edu (Peter J Desnoyers) Newsgroups: comp.lang.misc Subject: Re: From Modula to Oberon Message-ID: <3764@bloom-beacon.MIT.EDU> Date: 15 Mar 88 17:35:11 GMT References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: peter@athena.mit.edu (Peter J Desnoyers) Organization: Massachusetts Institute of Technology Lines: 38 In article <1557@pasteur.Berkeley.Edu> faustus@ic.Berkeley.EDU (Wayne A. Christopher) writes: >In article <2827@enea.se>, sommar@enea.se (Erland Sommarskog) writes: >> ... Ada as I see it have >> the perfect solution: The loop variable is declared in the FOR- >> statement, and is thus not accessible afterwards. >Here's the problem with that construct: I often write > > for (i = 0; i < max; i++) > if (something) > break; > if (i == max) > ... > > Wayne I've forgotten most of the CLU I learned, but I think the way to do that in a real language would be: for thing in what_i_want_from list[1..max] begin ... end except when empty ... where what_i_want_from is a user-defined iterator. I wish they had put iterators in Ada. C provides a general linear iterator, but in CLU you can iterate through a tree or anything else. After all, the idea of iterating is so that you can separate the structure of bunch of data from the logic of: for each foo in bar do something end Peter Desnoyers