How to use True, break and continue keywords in python ?

Today we will check the usage of few keywords in Python i.e. True, break and continue.

Usage of True, break and Continue

In below example, we will see how to use the keywords true, break and continue in python.

1. True:- Serves as 1 i.e. the condition is always true and runs an infinite loop.
2. Break:- Used to exit from loop.
3. Continue :- Skip execution of further statements after continue in loop and goes on top of loop again.

user@ngelinux$ cat newfile.py 
#!/usr/bin/python

i=0
while True:
	i+=1
	if i > 15:
		break
	if i % 2 == 0:
		continue
	print i
	
user@ngelinux$ 

Output

user@ngelinux$ ./newfile.py 
1
3
5
7
9
11
13
15
user@ngelinux$ 

Leave a Reply

Your email address will not be published.