Python Practice › Loop Programs › Program 80
Stop at 6 with a while loop
Write a Python program to print 1 to 10 but stop when the number is 6, using a while loop.
Output
1 2 3 4 5
Approach
breakleaves the loop.
Solution
n = 1while n <= 10: if n == 6: break print(n) n += 1Output
1 2 3 4 5
Learn the concept
New to this topic? Read the lesson, then come back.