I found a piece of code in an application that I'm giving continuity that I had not seen yet (or had never noticed). I casually always used i++
in a loop of repetition, for example, however in this section it was ++i
and I did not notice any difference in the result. Here is an example:
public static void main(String[] args) {
for (int i = 0; i < 10; ++i) {
System.out.println(i);
}
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
}
Is there any difference between i++
and ++i
? If so, which one would it be?