Python nested loops | Just enough Python

Publicado el: 23 September 2019
en el canal de: Ajay Tech
1,167
2

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 ()


En esta página del sitio puede ver el video en línea Python nested loops | Just enough Python de Duración hora minuto segunda en buena calidad , que subió el usuario Ajay Tech 23 September 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,167 veces y le gustó 2 a los espectadores. Disfruta viendo!