🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #174

Re: Unintuitive semantics for initializing in for statements

#174
From: Dave Berry
Date: Mon, 28 Apr 1986 13:12
16 lines
1406 bytes
In article <5334@alice.uUCp> shopiro@alice.UUCP writes:
>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.

An alternative would be to have a 'for' expression - the same as a 'for'
statement except that it returns the value of the iteration variable on
exit.  This satisfies your requirement to have such information available
while also avoiding the unintuitive behaviour noted by the original poster.

Mind you, I'm not convinced that the value of an iteration variable is needed
often enough in time-critical code for either system to be required.  An 
assignment in the loop body will give this info when its needed.
-- 
	Dave Berry. CS postgrad, Univ. of Edinburgh		
					...mcvax!ukc!cstvax!db
Technical Details
Message-ID: <101@cstvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!harvard!caip!seismo!mcvax!ukc!cstvax!db
References: <17195@rochester.ARPA> <5334@alice.uUCp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!harvard!caip!seismo!mcvax!ukc!cstvax!db
From: db@cstvax.UUCP (Dave Berry)
Newsgroups: net.lang.c++
Subject: Re: Unintuitive semantics for initializing in for statements
Message-ID: <101@cstvax.UUCP>
Date: Mon, 28-Apr-86 09:12:18 EDT
Article-I.D.: cstvax.101
Posted: Mon Apr 28 09:12:18 1986
Date-Received: Sat, 3-May-86 01:40:11 EDT
References: <17195@rochester.ARPA> <5334@alice.uUCp>
Reply-To: db@cstvax.UUCP (Dave Berry)
Organization: Comp. Sc., Edinburgh Univ., Scotland
Lines: 16