Article View: net.lang.c++
Article #179Re: Unintuitive semantics for initializing in for statements
From: rlb
Date: Sun, 27 Apr 1986 01:48
Date: Sun, 27 Apr 1986 01:48
28 lines
1737 bytes
1737 bytes
> The advantage in having the iteration variable declared in a for
> statement remain accessible is that you can test its value after
> the end of the loop.
>
> -- Jonathan Shopiro
As has been pointed out, the following construct commonly appears
in coding:
for(i = 0; i < MAX_I; ++i)
{
.
.
.
}
if(i >= MAX_I)
<code 'cause FOR loop "fell through">
In the true spirit of language diddling, how about allowing "else"
statements to bind with "for"s as well as "if"s? The "else" of
a "for" would be taken if the loop terminated "naturally". That is,
the "else" of a "for" would be skipped if the loop was exited by means
of a "break" statement. Of course, once you allow "for"s to have "else"s,
why deprive "while"s, and "do-while"s? This is not a tenable solution
in C++, since it would break some existing C programs (unless "else"s bound
to "if"s more strongly than they did to "for"s :-) Just a thought. Pros?
Cons? Gut-level feelings of revulsion?
{ihnp4|akgua|nsc}!zaiaz!rlb -Ron Burk
Technical Details
Message-ID:
<163@zaiaz32.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!mhuxm!mhuxf!mhuxi!mhuhk!mhuxt!houxm!whuxl!whuxlm!akgua!sb6!scbhq!uahcs1!madhat!zaiaz32!rlbReferences:
<17195@rochester.ARPA> <5334@alice.uUCp>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site zaiaz32.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!mhuxm!mhuxf!mhuxi!mhuhk!mhuxt!houxm!whuxl!whuxlm!akgua!sb6!scbhq!uahcs1!madhat!zaiaz32!rlb From: rlb@zaiaz32.UUCP Newsgroups: net.lang.c++ Subject: Re: Unintuitive semantics for initializing in for statements Message-ID: <163@zaiaz32.UUCP> Date: Sat, 26-Apr-86 21:48:54 EDT Article-I.D.: zaiaz32.163 Posted: Sat Apr 26 21:48:54 1986 Date-Received: Sat, 3-May-86 20:26:51 EDT References: <17195@rochester.ARPA> <5334@alice.uUCp> Organization: Zaiaz Communications. Huntsville, AL Lines: 28