My book Question 10
10. Which one of the following statements is not equivalent to the other two (assuming that the loop bodies are the same)?
a) for (i =0; i < 10; i++)
b) for (i =0; i < 10; ++i)
c) for (i =0; i++ < 10; )
I choose c, obviously it looks different, but the expr2 which is the control expression is exactly the same for a and b. and they start testing with i = 0. Option c increments i, (adds 1 to i) before the test. So we're not testing 0 < 10 like a and b. We're testing 1 < 10.
Is this the correct answer and do I have the correct reason?
10. Which one of the following statements is not equivalent to the other two (assuming that the loop bodies are the same)?
a) for (i =0; i < 10; i++)
b) for (i =0; i < 10; ++i)
c) for (i =0; i++ < 10; )
I choose c, obviously it looks different, but the expr2 which is the control expression is exactly the same for a and b. and they start testing with i = 0. Option c increments i, (adds 1 to i) before the test. So we're not testing 0 < 10 like a and b. We're testing 1 < 10.
Is this the correct answer and do I have the correct reason?