Check the semicolon after the loop...this will cause your loop to run, and only after completion the println will try to print...at which point i is equal to 5.