How to use Iteration statement In Python 3.8
Table of Contents
In this article I will teach you what is loop, how you will use multiple loops and types of loops in python.
Iteration statement is also called loops statement it allows to execute a block of statement when its condition is true. Loop statement is use when we need to run a code again and again, each time with different values.
Types of Iteration statement In Python 3.8
- While Loops
- For Loops
- Nested For Loop
How To Use While Loop In Python Explain With Example
In python the While Loop is used to execute a set of statement as long to given condition is true. And when its condition is false, the control is out come the loop.
While Loop Syntax:
While (condition):
Statement
Example Of While Loop In Python:
Example 01:
I want to Print out 0,1,2,3,4
So Write this coded in code editor
count= 0
while count < 5 :
print (count)
count +=1
The Output is:
Example 02:
In the following example, the statements in the loop continue to run until the index
variable is less than 5.
In python you can use while loop with multiple condition with if, if else statement.
Example# 03:
How to Use For Loop In Python With Example
For loop is use to for iterating over a sequence either may be a list, a dictionary, a tuple and set.
Example 01:
car = [“honda”, “toyota”, “bmw”, “audi”]
for x in car:
print (x)
For loop can iterating over a sequence of numbers using range and xrange functions. Following are the three different example range.
How To Use Nested Loops In Python 3.8
When one loop define in another loop its called Nested loop. We clear with the following simple example.
Example:
for i in range(1,5):
for j in range(0,i):
print(i, end=” “)
print(”)
Pingback: Free PHP MySQL POS With Source Code 2021 | GSS TECHNOLOGY