What is the difference between a For loop and a While loop?

Asked by kemiadewale · 6 months ago

1 Answer

27
amorebise · 6 months ago Top Answer

A For loop is for when you know exactly how many times you want to repeat (like for every day in a week). A While loop is for when you don't know (like keep running until the battery is 1%).

Be careful with While loops—if the condition never becomes false, the loop will run forever! We call that an 'Infinite Loop', and it can make your computer very hot.

Log in to add a comment.