You are on page 1of 8

If, elif, else Statements

An IF statement can be combined with an ELSE


statement
An ELSE statement contains the block of code that
executes, when conditional expression in IF statement
resolves to FALSE
ELSE is an optional statement to IF
Syntax : if, else
if test expression:
statement_1
else:
statement_2
Elif Statement
AN ELIF statement allows us to check multiple expressions for TRUE
value
Similar to else, An ELIF statement is an optional statement
There can be a number of ELIF statements which are following an
IF statement
Syntax : elif
if test expression_1:
statement_1
elif test expression_2:
statement_2
elif test expression_3:
statement_3
else:
statement_4
For Loop
For loop is used to iterate over elements of a sequence
It is often used when we have a piece of code which we want to
repeat "n" number of times
Syntax
for iterating_var in sequence:
Body of for loop
While Loop
While loop will continue to execute a block of code while
some condition remains true
Syntax
while some_condition:
Body of while
While Loop
Syntax
while some_condition:
Do something
else:
Do something different
break, continue , pass
break : Breaks out current closest loop
continue : goes to top of the closest enclosing loop
pass : does nothing

You might also like