🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Jim ADCOCK Mon, 30 Jul 1990 19:36
declarations in for loops
#260
Author: Jim ADCOCK
Date: Mon, 30 Jul 1990 19:36
15 lines
769 bytes
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]
Re: declarations in for loops
#214
Author: Steve Hastings
Date: Wed, 01 Aug 1990 18:11
10 lines
896 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:

What about while(), do...while(), and if() statements?
-- 
Steve "I don't speak for Microsoft" Hastings    ===^=== :::::
uunet!microsoft!steveha  steveha@microsoft.uucp    ` \\==|
Re: declarations in for loops
#241
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads