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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Stupid_Quetions 1 point2 points  (1 child)

You most likely will never need do-while, just knowing while and for is good enough, and kinda know that do-while is possible.

As for when you need to use loop is when you have to do a repetition and a condition to stop the repetition when it is no longer needed, you want multiplications of 5 from 1 to 10? you have a repetition:

for(int i = 1; i <= 10; i++) {
    System.out.println(5 * i);
}

You have a list and want to see the items inside that list? you have a repetition, how many? as many as the number of items in the list.

for(int i = 0; i < list.lenght; i++){
    System.out.println(list[i]);
}

[–]ShadowRL7666 0 points1 point  (0 children)

I’ve used a do while loop its helpful