2. Loop control statements change execution from
its normal sequence. When execution leaves a
scope, all automatic objects that were created
in that scope are destroyed. Python supports
the following control statements.
2
break
continue
pass
3. • The break statement
The break statement terminates the loop
containing it. Control of the program flows to
the statement immediately after the body of
the loop.
If break statement is inside a nested loop (loop
inside another loop), break will terminate the
innermost loop.
Syntax
break
3
5. • Python break program
for val in "string":
if val == "i":
break
print(val)
print("The end")
5
OUTPUT
s
t
r
The end
6. • Python continue statement
• The continue statement in Python returns the
control to the beginning of the while loop.
The continue statement rejects all the
remaining statements in the current iteration
of the loop and moves the control back to the
top of the loop.
• The continue statement can be used in
both while and for loops.
Syntax
continue
6
8. for val in "string":
if val == "i":
continue
print(val)
print("The end")
Python continue statement
OUTPUT
s
t
r
n
g
The end
9. • Python pass statement
• The pass statement in Python is used when a
statement is required syntactically but you do
not want any command or code to execute.
• The pass statement is a null operation; nothing
happens when it executes. The pass is also
useful in places where your code will
eventually go, but has not been written yet
(e.g., in stubs for example):
Syntax
pass
9
10. • Example program
for letter in 'Python':
if letter == 'h':
pass
print 'This is pass block'
print 'Current Letter :', letter
print "Good bye!"
10
OUTPUT
Current Letter : P
Current Letter : y
Current Letter : t
This is pass block
Current Letter : h
Current Letter : o
Current Letter : n
Good bye!