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.

Answered by Molly I. Python tutor

1501 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


How do you define a class in python


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


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


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo
Cookie Preferences