Using the comma
You can make the initialisation of more than one loop variables explicit by using the comma
int main()
{
int a, b;
for( a = 1, b = 4; a < b; a++, b--) {
cout << "a = " << a << endl;
cout << "b = " << b << endl;
}
}
Previous slide
Next slide
Back to first slide
View graphic version