+ 3
Confusion, x++ is adding 1 when we apply this in loop,why?
when we apply in loop, we write post increment x++ and postincrement add 1 after each cycle. for(i=0; i<10; i++) { System.out.println("Why this i++ add 1"); }
4 Respuestas
+ 8
i++ or ++i are equivalent (to i = i+1) when used as a standalone statement, which is the case here.
Post-incrementation doesn't mean that the incrementation isn't done.
Maybe your confusion stems from a wrong understanding of how a for loop works:
for(int i=0; i<10; i++) {
System.out.println(i);
}
is equivalent to:
int = 0;
while (i < 10) {
System.out.println(i);
i++;
}
Edit: Woops, thanks for the correction, Bobby.
+ 2
Just so you are aware, Zen's information is correct however his syntax is for a different language. instead of cout<<i<<endl, use System.out.println(i);
edit: nevermind, he fixed it. :)
0
The difference in priority
0
it is because the program contains counting backwards