what is a control statement what are the three types of control statement used in python
Answers
Answer:
A control statement is a statement that determines whether other statements will be executed. An if statement decides whether to execute another statement, or decides which of two statements to execute. ... for loops are (typically) used to execute the controlled statement a given number of times
Explanation:
Python provides us with 3 types of Control Statements:
- Continue
- Break
- Pass
#1) Continue Statement:
When the program encounters a continue statement, it will skip the statements which are present after the continue statement inside the loop and proceed with the next iterations.
Syntax:
continue
Example:
for char in ‘Python’:
if (char == ‘y’):
continue
print(“Current character: “, char)
Output:
Current character: P
Current character: t
Current character: h
Current character: o
Current character: n
In the above example during the second iteration if the condition evaluates to true, then it will execute the continue statement. So whatever statements are present below, for loop will be skipped, hence letter ‘y’ is not printed.
#2) Break Statement:
The break statement is used to terminate the loop containing it, the control of the program will come out of that loop.
Syntax:
break
Example:
for char in ‘Python’:
if (char == ‘h’):
break
print(“Current character: “, char)
Output:
Current character: P
Current character: y
Current character: t
#3) Pass Statement:
Pass statement is python is a null operation, which is used when the statement is required syntactically
Syntax:
pass
Example:
for char in ‘Python’:
if (char == ‘h’):
pass
print(“Current character: “, char)
Output:
Current character: P
Current character: y
Current character: t
Current character: h
Current character: o
Current character: n
I hope it helps u dear friend ^_^♡♡