Shervin Asgari Shervin Asgari - 1 month ago 12
Java Question

do while syntax for java

Ages since I have written a do while.

Whats wrong with this do while

int i = 0;
do {
System.out.println(i);
} while(++i == 500);


I only goes once through the loop, and IMO it should iterate 500 times.

Answer

You probably meant

while (++i < 500);

instead of

while (++i == 500);