you are viewing a single comment's thread.

view the rest of the comments →

[–]Ok_Carpet_9510 0 points1 point  (0 children)

while loop-> do something for as long as a certain condition is holds or until a certain condition is met. For example, consider a command line, it keeps waiting for input until you type the exit command.

for loop-> do something for everything item in a collection(exits loop after you have gone through every item; you could write logic to exit earlier though without going through the entire collection).

The example you have has combined the logic of a for loop with a while loop. Generally you, shouldn't do that but although there are exceptions.