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

A while loop is used in situations where we do not know how many times a loop needs to be executed beforehand.A for loop is used where we already know the number of times loopneeds to be executed.For example, imagine we want to create an animation of someone skipping using a rope. A WHILE loop would be useful if you want to create a program that has the animation of someone skipping till the user says stop.A FOR loop would be useful if you know how many times you want the animation of someone skipping to run.

Answered by Alex Z. Python tutor

1395 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What is the difference between a cycle "if" and "while"?


Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


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