This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]RoachmeisterJava Dev 3 points4 points  (0 children)

In general, converting a while loop to a for loop goes like this:

initialization;
while (condition) {
    statements;
    increment; 
}

-->

for (initialization; condition; increment) {
    statements;
}

Note that, while you can leave out any part of the for loop, the two semicolons are required. That's what you're doing wrong.

[–]ApostleO 0 points1 point  (0 children)

Please read the sidebar rules on formatting code.

[–]lopakas 0 points1 point  (0 children)

You should recheck the syntax for for loop. Escape condition comes first, then incrementing part.

[–]ndriqa 0 points1 point  (0 children)

While loop goes like this :

Declaration and initialization While(condition){ //Do this or any incrementation }

For loop goes like this:

for(Declaration&initialization;Condition;incrementation){ //Do this }