For Loop
1 2 3 4 5 6
|
int a = 5;
for (int ctr = 0; ctr < 4; ctr++)
a = a - 1;//1
a = a + 3;//2
cout << a << endl;
|
I need to know whether you need to evaluate both //1 & //2 after the loop or just //1?
what you wrote could also be written like this:
1 2 3 4 5 6 7 8
|
int a = 5;
for (int ctr = 0; ctr < 4; ctr++){
a = a - 1;//1
cout << a << endl;
}
a = a + 3;//2
cout << a << endl;
|
and then you could see what is happening.
if you want it to do both write it like this:
1 2 3 4 5 6 7
|
int a = 5;
for (int ctr = 0; ctr < 4; ctr++){
a = a - 1;//1
a = a + 3;//2
}
cout << a << endl;
|
I hope I did not misunderstand your question.
Ok, I think I know why the ans is 4 now. Tks.
Topic archived. No new replies allowed.