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

A for loop will run the code a predetermined number of times, whereas a while loop will continue to execute the code until a predetermined condition is met.

MI

Related Python Mentoring answers

All answers ▸

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


Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.


What is the difference between a cycle "if" and "while"?


Write a function that checks whether a number is prime or not.