Loop Control Statements
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.
Continue , break and pass
Continue--> It returns the control to the beginning of the loop.
for x in 'python developer':
if x == 'e' or x == 'o':
continue
print('Current Letter :', x)
Output will be each letter in python developer but without e and o. they continue
even after that.
151
Break--> It brings control out of the loop.
for x in 'python developer':
# break the loop as soon it sees 'e' or 'o'
if x == 'o' or x == 'e':
break
print('Current Letter :', x )
Output will be ‘o’ , because it will stop looping after it sees o or e.
Pass -->We use pass statement to write empty loops. Pass is also used for
empty control statements, function and classes.
for x in “python developer”:
Pass
Print(“last letter:”,x)
Output will be the last letter of the word which is ‘r’.
152