Loop control statements
- Break statement – Breaks the loop statement
- Continue statement – skips the loop body and continue
- Pass statement – execute nothing
Break statement
It terminates the loop and transfers execution to the next statement of the next statement of the loop immediately in the program
Syntax
break
Example
for letter in “S.M. Security”:
if letter==“M”:
break
print(“The current letter is :”, letter)
Output
The current letter is: S
The current letter is: .
Continue statement
The continue statement is used to skip the rest of the code inside a loop for the current iteration only. It is used to transfer the control to the beginning of the loop
Syntax
continue
Example
for letter in “Python”:
if letter==“h”:
continue
print(“The current letter is :”, letter)
Output
The current letter is: P
The current letter is: y
The current letter is: t
The current letter is: o
The current letter is: n
Pass statement
- Pass statement execute nothing
- It results in no operation
Syntax
pass
Example
for letter in “Python”:
if letter==“h”:
pass
print(“The current letter is :”, letter)
Output
The current letter is: P
The current letter is: y
The current letter is: t
The current letter is: h
The current letter is: o
The current letter is: n

No comments:
Post a Comment