10
I found an excerpt of code in an application that I’m continuing that I hadn’t seen before (or never noticed). Casually I always used i++
in a loop of repetition, for example, however this passage contained ++i
and I didn’t notice any difference in the result. See below 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 yes, which(is) would be(m)?
Related: What is the difference between pre and post increment in Javascript?
– Marconi