Loops can be nested within each other. For example, here is how you print each number ( from 1 to 10 ) as many number of times.
for i in range(1,11) :
for count in range(0,i) :
print ( i, end=" ")
print ()
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10
You can do the same with while loops as well. You can nest for loop inside a while loop and vice-versa. Here is a re-write of the same program as above nesting a while loop inside a for loop.
for i in range(1,11) :
count = i
while count > 0 :
print ( i, end=" ")
count = count - 1
print ()
On this page of the site you can watch the video online Python nested loops | Just enough Python with a duration of hours minute second in good quality, which was uploaded by the user Ajay Tech 23 September 2019, share the link with friends and acquaintances, this video has already been watched 1,167 times on youtube and it was liked by 2 viewers. Enjoy your viewing!