Topic: Q: Multiple declarations in for loop?


Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/05/19
Raw View
Cristian Georgescu <cgeorges@lehman.COM> writes:

> Does the language allow the definition of multiple variables in a for
> loop?

Only if they're all of the same type:

for (int i=0, j=0; ...

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


[ 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              ]






Author: Oleg Zabluda <zabluda@math.psu.edu>
Date: 1998/05/20
Raw View
Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
: Cristian Georgescu <cgeorges@lehman.COM> writes:

: > Does the language allow the definition of multiple variables in a for
: > loop?

: Only if they're all of the same type:

: for (int i=0, j=0; ...

Or you can do something of this sort:

for( pair<int, unsigned> p(1, 2u);
     p.first < 10 && p.second < 20u;
     ++p.first, ++p.second )

Oleg.
--
Life is a sexually transmitted, 100% lethal disease.


[ 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              ]






Author: Cristian Georgescu <cgeorges@lehman.COM>
Date: 1998/05/19
Raw View
Does the language allow the definition of multiple variables in a for
loop?

F.I.: the compiler I am using (VC5.3) is accepting the following:

int j=0;
for (int i=0; i<10,j<10; i++, j++)
{
 //...
}

but does not accept the following:

for (int i=0, int j=0; i<10,j<10; i++, j++)
{
 //...
}

Is this in the standard or it is just a compiler bug?
--
                      Cristian Georgescu
_________________________________________________
                      email: CGeorges@lehman.com
                      tel:   (212) 526-3502

    _/      _/_/_/_/  Lehman Brothers
   _/      _/    _/   Equity Finance Systems
  _/      _/_/_/_/    World Financial Center
 _/      _/    _/     200 Vesey Street
_/_/_/  _/_/_/_/      New York, NY 10285.
_________________________________________________
---
[ 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              ]