Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Python » Python programs

Python | Examples of loops (based on their control)



Python loop examples based on their control: Here, we are writing examples of Range Controlled loop, Collection Controlled, Condition Controlled Loop.
Submitted by Pankaj Singh, on October 09, 2018

Based on loop controls, here are examples of following types:

  1. Condition Controlled Loop
  2. Range Controlled loop
  3. Collection Controlled loop

1) Condition Controlled Loop

# 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

#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

#Collection Controlled Loop
fruits=["apple","banana","guava","grapes","oranges"]
for item in fruits:
    print(item)

Output

apple
banana
guava
grapes
oranges





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.