Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
• Live Instructor-led Classes
• Expert Education
• 24*7 Support
• Flexible Schedule

## Control Flow Statements:

In this module we will be discussing one of the most important building blocks of Python Programming Language.
The ability to change the behavior of a piece of code which is based on certain information in the environment is known as conditional code flow. The conditional logic in Python is primarily based on the “if … else” structure.

Here, we will be discussing:

Learn Python in 16 hrs from experts

## If Statement

If-statement is used to test a condition, if-condition is true then the code inside the if statement is executed otherwise that code is not executed.

Syntax:

if condition :
statement

e.g.

i=1
if i==1:
print “Hello intellipaat”Output –
Hello intellipaat

### If-else

If else is also used to test a condition, if condition is true then the code inside the if statement is executed otherwise else part is executed.

Syntax:

If condition:
statements
else:
statements

e.g.

i=1
if i==2:
print (“Hello intellipaat”)
else:
print (“Hello”)
Output
Hello

### Nested If

It contains multiple if else condition. It is used to check the multiple conditions. This statement is like executing a if statement inside an else statement.

Syntax:

if condition1:
statement
if condition2:
statement
elif condition3:
statement
else
statement

e.g.

i = 1
if i < 3:
print (“i is less than 3”)
if i == 2:
print (“value of I is equal to 2”)
elif:
print (“value is not equal to 2”)
else:
i is less than 3
value is not equal to 2

## Python break

It is a jump statement which is used to transfer the control to the end of loop.

e.g.

for i in [10,20,30,40]:
if i==30:
print (“Item Found”)
break
print (i)Output
10
20
Item Found

## Python Continue Statement

It is also a jump statement which is used to skip the current statement and forces to execute next iteration.

e.g.

for i in [10,20,30,40]:
if i==30:
print(“Item Found”)
continue
print(i)Output
10
20
Item Found
40
Become Python Certified in 16 hrs.

close

## Loops:

### While Loop

In this body is executed until the condition is true. Once the condition becomes false then control comes out the loop.

Syntax:

while condition:
A body of while loop

e.g.

i = 10
while i>5:
print(i)
i=i-1Output
10
9
8
7
6

### For Loop

For loop executes the sequence of code according to the specified times and conditions.

Syntax:

for a variable in sequence:
A body of for loop

e.g.

i=1
for i in range(1,8):
print 2*i
Output
2
4
6
8
10
12
14

### Nested Loop

Loop defined within another loop is known as nested loops.

Syntax:

for condition1:
for condition2:
Body of for loop

This brings us to the end of the python loops. In the next module of Intellipaat’s Python Tutorial, we will be discussing the functions and see how they work.

Further check our Python online course for certification and prepare yourself with our free Python interview questions listed by the experts.

Previous Next

Learn SQL in 16 hrs from experts

### "0 Responses on Python Control Flow Statements"

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

## Sales Offer

• To avail this offer, enroll before 19th February 2019.
• This offer cannot be combined with any other offer.
• This offer is valid on selected courses only.
• Cashback will be accumulated in Intellipaat e-wallet
• Please use coupon codes mentioned below to avail the offer