From 7393592954998781539 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,de99e5c46dfe5a28 X-Google-Attributes: gidf78e5,public From: James Kuyper Subject: Re: Multiple declarations in for loop? Date: 1998/05/26 Message-ID: <356A4155.2781@wizard.net>#1/1 X-Deja-AN: 356675344 X-NNTP-Posting-Host: gscsgi02.gsfc.nasa.gov Content-Transfer-Encoding: 7bit Approved: stephen.clamage@sun.com (comp.std.c++) References: <356196A0.4214@lehman.com> <6jsdc4$fvr@engnews1.Eng.Sun.COM> <6jutcg$96n@marianna.psu.edu> X-UID: 0000000001 X-Status: $$$T Content-Type: text/plain; charset=us-ascii Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Mime-Version: 1.0 Newsgroups: comp.std.c++ Originator: clamage@taumet Oleg Zabluda wrote: > > Steve Clamage wrote: > : In article 4214@lehman.com, Cristian Georgescu writes: > : >> Only one simple-declaration is allowed. The following declares i and j as > : >> you wish > : >> for (int i=0, j=0; i<10,j<10; i++, j++) ... > : > > : >Is there a reason for this limitation (only one simple declaration); > : >why not: > : > > : > for (int i=0, unsigned int j=0; i<10,j<10; i++, j++) ... > > : You can't write > : int i=0, unsigned int j=0; > : in any context, so it would be odd to allow it in a for-loop header. > : The comma in a declaration separates declarators, it doesn't end > : a declaration. > > It would be odd, but I think it would be worth it, because > it is frequently needed, and the alternatives are pretty > ugly. If the goal is to reduce oddity, maybe allowing > it in all other relevant contexts would be a solution :-) ? > Unless it would break something else, of course. I don't think that the following is very ugly, just a little clumsy: { unsigned int j; for(int i=0; i<10 && /* Note correction */ j<10; i++, j++) { // Loop body; which presumably changes i or j, but not // always in the same way; otherwise j is redundant. } } [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]