Thomas Sundberg

August 5, 2011

What is the difference between i++ and ++i?

Filed under: Clean Code, Java, Programming, Teaching — Tags: , , , — Thomas Sundberg @ 18:27

During a coaching session I got a question about a loop.

Would there be any difference in the output from a loop defined as

for (int i = 0; i < 3; i++) {
    System.out.print(i + " ");
}

and a loop defined as

for (int i = 0; i < 3; ++i) {
    System.out.print(i + " ");
}

in Java?

(more…)

Theme: Customized Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 41 other followers