What is the difference between a for and a while loop?

A for loop iterates over set commands within the loop (need to be indented), executing this block of code in order until prompted to stop (as specified). A while loop is used when a condition needs to be checked each iteration before the loop can run through the block of code.

TD

Related Python Mentoring answers

All answers ▸

What is the difference between a for loop and a while loop.


How do For Loops work?


Manually implement a function that finds the smallest value in a list of integers and print it.


Write a short program to print all the even numbers 1 to 100