Welcome back to another Python video. Today we look at the difference between for vs while loops:
You use a for loop to iterate over a collection of a finite number of items.
You use a while loop when the number of loops is not known.
We show a couple of simple examples and as while loops are less common, we also dug up two more examples from our coding platform.
We also show a lesser-known construct: for...else (which also would work with a while loop).
Hope this helps distinguish between the two type of loops better.
Please comment below if you want to see videos on more beginner topics ... thanks.
On this page of the site you can watch the video online For vs while loops in Python: when to use each + practical examples with a duration of hours minute second in good quality, which was uploaded by the user Pybites 29 March 2023, share the link with friends and acquaintances, this video has already been watched 4,285 times on youtube and it was liked by 38 viewers. Enjoy your viewing!