Description: Control flow statements in Python are used to control the flow of execution of a program. They determine the order in which different statements or blocks of code are executed based on certain conditions or loops.
Step-by-Step Process
Control flow modifiers: These statements are used to alter the flow of loop. Break statement: Exits the current loop (either for or while) entirely, regardless of the loops condition. continue statement: Skips the current iteration of the loop and moves to the next iteration Pass statement: It is Used as a placeholder when no action is required.
Sample Code
#Condition Statement
print("Output for condition statement:")
a = 10
if a > 5:
print("a is greater than 5")
else:
print("a is not greater than 5")
print()
#Control flow modifiers
#Break
print("Output for break statement:")
for i in range(10):
if i == 5:
break
print(i)
print()
#Continue
print("Output for continue statement:")
for i in range(10):
if i == 5:
continue
print(i)
print()
#Pass Statement
print("Output for pass statement:")
for i in range(5):
if i == 3:
pass
print(i