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

Python control flow and functions · Freshers

Model answer

A for loop iterates over a sequence or any iterable: for item in items. A while loop repeats as long as a condition is True, and you must make sure the condition eventually becomes False. Use for when you know what you iterate over, while when you wait for a condition.

Learn this topic

Functions in Python: def, Arguments and return in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions