+ 1
Increments in for loop
for(int x = 0; x <10; x++){System.out.print(x);} Shouldn't this increment x by 1 before it reaches print(x);} ? i cant see any diffrence as ++x x++ both outputting 0123456789? also im assuming becuase 10<10 is false this terminates the loop.?
2 Respuestas
0
I only use x++ in the for parameter. elsewhere, I use x+=1;
0
This is what you should know. Whether you use x++ or ++x, you will get the same result. Take note of this important point though, if for instance x=1; ++x will give you 2 when you print it out where as x++ will give you 1. 1 because thats a post increment meaning telling the pc that okay, I need you to add 1 to my current value after displaying it.