Path: utzoo!attcan!uunet!decwrl!sgi!shinobu!odin!thebeach.wpd.sgi.com!shap From: shap@thebeach.wpd.sgi.com (Jonathan Shapiro) Newsgroups: comp.std.c++ Subject: Re: declarations in for loops Message-ID: <11292@odin.corp.sgi.com> Date: 2 Aug 90 18:03:20 GMT References: <56168@microsoft.UUCP> Sender: news@odin.corp.sgi.com Reply-To: shap@sgi.com Organization: Silicon Graphics, WorkGroup Products Division Lines: 34 In article <56168@microsoft.UUCP>, jimad@microsoft.UUCP (Jim ADCOCK) writes: > Proposed: > > That the traditional C++ ability to declare variables in for loops > be maintained, and maintain its traditional meanings, for example: > > doFoo() > { > for (int i=0; i<100; ++i) > for (int j=0; j doSomething(i,j); > } > > *is* legal, and i's and j's scopes extend to the end of doFoo(). > > [disclaimer: this represents the opinions of an individual C++ user] This would be wrong. The correct scope rule is that i's and j's scopes extend to the end of the scope in which the for() statement appears. Consider the example doFoo() { { for (int i = 0; i < 100; ++i) for (int j=0; j