Is it possible to declare two variables of different types in a for loop?
No - but technically there is a work-around (not that i'd actually use it unless forced to):
for(struct { int a; char b; } s = { 0, 'a' } ; s.a < 5 ; ++s.a)
{
std::cout << s.a << " " << s.b << std::endl;
}
Not possible, but you can do:
float f;
int i;
for (i = 0,f = 0.0; i < 5; i++)
{
//...
}
Or, explicitly limit the scope of f
and i
using additional brackets:
{
float f;
int i;
for (i = 0,f = 0.0; i < 5; i++)
{
//...
}
}