Python Practice › Loop Programs › Program 80

Stop at 6 with a while loop

EasyLoop Programs · 80 of 90

Write a Python program to print 1 to 10 but stop when the number is 6, using a while loop.

Advertisement
Output
1
2
3
4
5

Approach

  1. break leaves the loop.

Solution

Python
n = 1while n <= 10:    if n == 6:        break    print(n)    n += 1
Output
1
2
3
4
5

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs

Leave a Comment