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:
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.
print “Hello intellipaat”Output –
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.
print (“Hello intellipaat”)
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.
if i < 3:
print (“i is less than 3”)
if i == 2:
print (“value of I is equal to 2”)
print (“value is not equal to 2”)
print (“Not found the true expression”)Output
i is less than 3
value is not equal to 2
print (“Item Found”)
Python Continue Statement
In this body is executed until the condition is true. Once the condition becomes false then control comes out the loop.
A body of while loop
For loop executes the sequence of code according to the specified times and conditions.
A body of for loop
for i in range(1,8):
Loop defined within another loop is known as nested loops.
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.