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.

Answered by Tutor143011 D. Python tutor

1390 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Explain how python programs are structured and give an example of how methods are initiated


[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


What would output this code? print(hello world)


Write a simple Python program that asks a user to input their age and name and then return the text: "Hi my name is *NAME*, and I am *AGE* years old."


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