Use else with while loop in Python

Use else with while loop in Python

Instructor-svgAl-Mamun Sarkar
Mar 25 , 2020

Use else with the while loop in Python programming language. 

n = 1
while n <= 10:
    print(n)
    n = n + 1
else:
    print('The loop is over.')

 

Output:

1
2
3
4
5
6
7
8
9
10
The loop is over.

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram