Nested Loops :

An inner loop within the repeating block

of an outer loop is called Nested Loop.

nested-loops.webp

Examples - Nested Loops

Example - 1: While loop inside a For loop

Example - 2: While loop inside a while loop

Example :

for i in range(2):
  print("Outer: " + str(i))
  for j in range(2):
    print(" Inner: " + str(j))
Outer: 0
 Inner: 0
 Inner: 1
Outer: 1
 Inner: 0
 Inner: 1

Practice Questions :