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.

TD
Answered by Tutor143011 D. Python tutor

1520 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Create an algorithm that can be used as a guessing game. Make sure to import random at the start.


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


How would you get a piece of code to print the numbers 1 to 10


How could I write a program to convert Km/h to m/s in python


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences