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

Related Python Mentoring answers

All answers ▸

How might we implement the bubble sort algorithm in Python


What is the difference between using range() and a list of values?


Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.


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