Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!topaz!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c++ Subject: Re: Unintuitive semantics for initializing in for statements Message-ID: <805@bentley.UUCP> Date: Fri, 9-May-86 20:39:07 EDT Article-I.D.: bentley.805 Posted: Fri May 9 20:39:07 1986 Date-Received: Sun, 11-May-86 04:25:37 EDT References: <17195@rochester.ARPA> <5334@alice.uUCp> <101@cstvax.UUCP>, <224@tuck.nott-cs.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 30 In article <224@tuck.nott-cs.UUCP> nott-cs!anw (Andy Walker) writes: >In article <101@cstvax.UUCP> db@cstvax.UUCP (Dave Berry) writes: >> An alternative would be to have a 'for' expression - the same as a 'for' >> statement except that it returns the value of the iteration variable on >> exit. Not all "for" statements *have* an iteration variable. > The trouble with all such suggestions is that there are too many >things that a loop *could* deliver, and for every application that would >make use of one such thing, there are equally worthy applications for all >the others. Further, there is always a cogent objection. For example, >you could return: > > a) The value that the iteration variable would have on the next cycle > [ie, the value that caused termination] -- but this could easily > be > maxint. If so, you've already got a problem (probably infinite loop). Remember, a "for" is just a glorified "while". >... Better to have nothing than to spread such confusion! I ran into these same problems some years ago when designing a language with statement-expression equivalence. I concluded that a loop has a void value. In C++, it's not so bad having statements which are not expressions, because you can just make a one-statement inline function and use "return". Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint