home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!news.centerline.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!cs.utexas.edu!uwm.edu!linac!att!cbnewsc!cbfsb!cbnewsg.cb.att.com!nh
- From: nh@cbnewsg.cb.att.com (nicholas.hounsome)
- Subject: Re: Bad 'for' statement?
- Message-ID: <1992Nov13.085913.1912@cbfsb.cb.att.com>
- Sender: news@cbfsb.cb.att.com
- Organization: AT&T
- References: <1992Nov12.160420.18097@rs6000.bham.ac.uk>
- Date: Fri, 13 Nov 1992 08:59:13 GMT
- Lines: 53
-
- From article <1992Nov12.160420.18097@rs6000.bham.ac.uk>, by pickerig@eee.bham.ac.uk (Mr. G. Pickering):
- > Hi,
- >
- > Could you tell me if this is really a syntax error as AT&T 2.1 reports?
-
- Yes it is.
-
- >
- > for(int i=0, int j=10; i<10; i++, j++)
- > {
- > // do something
- > }
-
- The first part must be either an expression or a declaration statement.
-
- The usual C
-
- for(i=0,j=10 ...
-
- is an expression in which ',' is an operator NOT a separator - this tends to be
- overlooked because ',' is rarely used as an operator.
- If you wrote:
-
- int i=0, int j = 10;
-
- You would not expect it to compile and so it wont in the "for".
- Of course in this case it is possible to write:
-
- for(int i=0,j=10;...
-
- Since the first part is a valid declaration statement. One can even have ints
- , arrays of ints, functions returning int or any combination of these but not
- an int and a short say. It is only included as a convenience for a
- common programming construct and IMHO it was a mistake. (It would have
- been better if the scope was limmited to the for loop - what I find is
- that I want several fors and I cannot use the same variable in each.
-
- >
- > Thanks,
- >
- > Guy
- >
- > --
- > +--------------------------------+-----------------------------------------+
- > | Guy Pickering | School of Electronic & Electrical Eng, |
- > | E-MAIL: G.PICKERING@uk.ac.bham | University of Birmingham, |
- > | Tel: (021) 414 4340 | Edgbaston, Birmingham. B15 2TT. |
- > +--------------------------------+-----------------------------------------+
- > | "I have ten pairs of trainers...One for each day of the week" - Sam Fox |
- > +--------------------------------+-----------------------------------------+
-
- Nick Hounsome
- AT&T Network Systems UK Ltd.
-