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
Answered by Molly I. Python tutor

1573 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

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


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.


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


Give a segment of python code that will print the numbers 1 to 7, each one on a new line


We're here to help

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

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences