I have a question about counting in a FOR loop
My mind can't comprehend this.
for(int x = 3; x < 10; x++)
Why does this only count to 9?
9 is less (<) than 10, so i would assume that it would count X one more time.
I have a question about counting in a FOR loop
My mind can't comprehend this.
for(int x = 3; x < 10; x++)
Why does this only count to 9?
9 is less (<) than 10, so i would assume that it would count X one more time.
Never mind.
I guess the loop won't run if X equals the number
You need to post the body of the for loop, so that we can confirm that is only "counts" to 9.
If you are printing x inside the body of the for loop, I would only expect to see values up to 9 printed.
If you are printing x after the body of the for loop, I would expect a compiler error, since x goes out of scope when the for loop ends.
x will start at 3, be incremented by one each loop and the loop will terminate if (when) x is no longer less than 10.
x will then = 3-9 or 7 turns
it will run until x=10 this way:
for (int x = 3, x <= 10; x++)