From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,4873305131bf4d94 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public From: Matt Austern Subject: Re: Porting (was ADA and Pascal etc) Date: 1997/10/31 Message-ID: #1/1 X-Deja-AN: 286230054 References: <34557f2b.1934172@news.mindspring.com> <63bhta$g2e@bgtnsc03.worldnet.att.net> <345AB871.413A@dynamite.com.au> <63d3sm$ap7$3@darla.visi.com> Organization: SGI Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-10-31T00:00:00+00:00 List-Id: seebs@plethora.net (Peter Seebach) writes: > Your problem here is that C++ is random. There have been holy wars > fought among the faithful over whether i's scope should end at the > end of the loop (those aren't parens, btw, they're braces), or > should continue into the surrounding code. The "rationale" (hah!) > given by the "surrounding code" fanatics is > for (i = 0; i < 20; ++i) > if (condition) > break; > - they want to be able to see whether or not i made 20 The draft C++ standard is quite specific, and not at all random. If you write for (int i = 0; i < N; +i) { // loop body } then the scope of the variable i does not extend past the end of the loop. The same holds for while loops and if statements. > C9X, of course, has the scope end with the end of the for; if you > want i to scope beyond the for, declare it outside the for. For C89 and C9X, the issue does not arise. Neither the C89 standard nor the draft C9X standard allows variables to be declared in the controlling expression of for, while, or if. I don't know whether Ada has any constructs where an analogous issue arises.