Home »
Python »
Python Programs
Python | Examples of Loops Based on Control Type
Python loop examples based on their control: Here, we are writing examples of Range Controlled loop, Collection Controlled, Condition Controlled Loop.
By Pankaj Singh Last updated : April 13, 2023
Examples of Loops Based on Control Type
Based on loop controls, here are examples of following types:
- Condition Controlled Loop Example
- Range Controlled Loop Example
- Collection Controlled Loop Example
1. Condition Controlled Loop Example
# Condition Controlled Loop
a=1
while a<=10:
print(a)
a=a+1
Output
1
2
3
4
5
6
7
8
9
10
2. Range Controlled Loop Example
#Range Controlled Loop
#range(end) start=0,step=+1
for i in range(10):
print(i,end=" ")
print("\n")
#range(start,end) step=+1
for i in range(1,11):
print(i,end=" ")
print("\n")
#range(start,end,step)
for i in range(1,11,3):
print(i,end=" ")
print()
for i in range(10,0,-1):
print(i,end=" ")
Output
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 4 7 10
10 9 8 7 6 5 4 3 2 1
3. Collection Controlled Loop Example
#Collection Controlled Loop
fruits=["apple","banana","guava","grapes","oranges"]
for item in fruits:
print(item)
Output
apple
banana
guava
grapes
oranges
Python Basic Programs »