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.

TD

Related Python Mentoring answers

All answers ▸

Define a function that takes in the age of the user and adds it to an output sentence such as "You are ..... old".


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


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.


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.