🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #241

Re: declarations in for loops

#241
From: Jonathan Shapiro
Date: Thu, 02 Aug 1990 18:03
34 lines
1332 bytes
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<i; ++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<i; ++j)
				doSomething(i,j);
		...
	} /* scope of i and j ends here */
} /* definitely NOT here */

It's been my experience that this feature causes confusion.

Jon
Technical Details
Message-ID: <11292@odin.corp.sgi.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!sgi!shinobu!odin!thebeach.wpd.sgi.com!shap
References: <56168@microsoft.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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