Python OOPs


Python SQLite


Examples


Others


Python Break Statement


The break statement used to terminate the loop.If break statement is inside of another loop, it will terminate only current loop.

Write a Python program for break statement with for loop.

Example 1
for i in range(10):
    if i==5:
        break
    print(i)
Output
1
2
3
4

Write a Python program to print all Prime Numbers in an Interval.

Example 2
lower_limit=int(input("Enter lower Limit : "))
upper_limit=int(input("Enter upper Limit : "))
print("Prime Numbers are")
for n in range(lower_limit,upper_limit+1):
    if n > 1:
        for i in range(2,n):
            if (n%i)==0:
                break
        else:
            print(n)
Output
Enter lower Limit : 10
Enter upper Limit : 20
Prime Numbers are
11
13
17
19