home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!unixhub!redwing.SLAC.Stanford.EDU!kelsey
- From: kelsey@redwing.SLAC.Stanford.EDU (Mike Kelsey)
- Subject: Re: Bad 'for' statement?
- Message-ID: <BxM32o.6EI@unixhub.SLAC.Stanford.EDU>
- Keywords: AT&T for
- Sender: news@unixhub.SLAC.Stanford.EDU
- Organization: Stanford Linear Accelerator Center
- References: <1992Nov12.160420.18097@rs6000.bham.ac.uk>
- Date: Thu, 12 Nov 1992 16:27:59 GMT
- Lines: 34
-
- In article <1992Nov12.160420.18097@rs6000.bham.ac.uk>, pickerig@eee.bham.ac.uk (Mr. G. Pickering) writes:
- |> Hi,
- |>
- |> Could you tell me if this is really a syntax error as AT&T 2.1 reports?
- |>
- |> for(int i=0, int j=10; i<10; i++, j++)
- |> {
- |> // do something
- |> }
-
- Yes it is. GCC 2.3.1 also calls it an error, claiming that the function 'j' is
- undeclared. You can fix it by eliminating the second 'int', since the comma in
- that construction does it for you. Here is a complete sample program:
-
- #include <stdio.h>
- int main()
- {
- for (int i=0, j=10; i<10; i++, j++)
- printf("\n i=%d, j=%d",i,j);
- }
-
- |>
- |> Thanks,
- |>
- |> Guy
-
- You're welcome. :-)
- -- Mike Kelsey
- --
- [ My opinions are not endorsed by SLAC, Caltech, or the US government ]
- "I've seen things you people wouldn't believe. Attack ships on fire off
- the shoulder of Orion. I've watched C-beams glitter in the darkness
- near the Tannhauser Gate. All these memories will be lost in time, like
- tears in the rain." -- Roy Batty
-