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