Python Practice › Loop Programs › Program 81

Stop at 6 with a for loop

EasyLoop Programs · 81 of 90

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

Advertisement
Output
1
2
3
4
5

Approach

  1. break leaves the for loop.

Solution

Python
for n in range(1, 11):    if n == 6:        break    print(n)
Output
1
2
3
4
5
Advertisement

Learn the concept

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

More loop programs

← All 90 Loop Programs