Python for Loop

There are some conditions where we need to  repeat the logic for some times (finite(or) infinite) then in such cases , we need to use loops. We continues the execution of loops until the condition becomes false.  Python supports three types of python for loop.

Would you like to know Why python is important for Android apps, Read More

While loop:

It repeats the statement (or) group of statements until the python while condition is true. It initially checks the conditions before the execution of the loop.  If the condition satisfies then it moves into the body of the loop. We use this loop when we are not sure how many types the loop must repeat.

Python for Loop








count = 1

while (count < 5 ):


   count = count *  2

print(“Good bye!”)

Output :




Good bye!

Visit Python online training for more coding examples on While loop

For loop :

Like while loop for loop allows the block of code to be repeated certain number of time.The major difference between while and for loop is that, in python for loop we know the number of iteration required to break the loop.

Python for Loop

Syntax :

For variable in sequence:


Ex :

flowers  = [‘jasmine’, ‘Rose’,  ‘lilly’]

for index in range(len(flowers)):

  print (flowers[index])

Output :




Nested loop:

If there is loop with in a loop then we call it as nested loops . It can be a while loop with in a for loop and vice versa.

Python for Loop

EX :

count = 1

for i in range(5):

   print(str(i) * i)

   for j in range(0, i):

       count = count + 1

Visit  best python course for more coding examples

to our newsletter

Drop Us A Query

Trending Courses
  • Pega testing training
    PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • blockchain course
    Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • ethical hacking course
    Ethical Hacking Certification Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • python training
    Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
    Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • what is pega
    PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).

100% Secure Payments. All major credit & debit cards accepted.