Control Structures Python
Control Structures Python
If …elif… else statements: If we want to check more than one condition we can use
the elif statements. If a condition is true then the statements within the if block
will be executed. If the condition is false, we can provide an elif statement with a
second condition and the statements within the elif block will be executed only
when the condition is true. We can provide multiple elif statements and an else
statement at the end if all the above conditions are false.
Syntax:
if condition:
True Statements
elif condition2:
True Statements
elif condition3:
True Statements
…….
else:
False Statements
Loops in Python
Syntax:
while condition:
statement(s)
increment/decrement
Break and Continue Statement
break statement: This statement is used to terminate the loop it is present in. Control
goes outside the loop it is present in. If a break statement is present in a nested
loop, it only comes out of the innermost loop.
Syntax:
while condition:
statments
if condition:
break
statements
Continue statement: This statement is used to skip the current iteration. The loop will
not be terminated, it just won’t execute the statements below the continue
statement. The incrementing will be done in for loop. If the increment statement
is written below continue, it won’t be executed in while loop.
Syntax:
while condition:
statement(s)
if condition:
continue
statements
Pass Statement