Python for Loop

Click to rate this post!
[Total: 0 Average: 0]

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

Syntax:

initialization

While(condition)

{

statements

}

Ex:

count = 1

while (count < 5 ):

   print(count)

   count = count *  2

print(“Good bye!”)

Output :

1

2

4

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:

Statements

Ex :

flowers  = ['jasmine', 'Rose',  'lilly']

for index in range(len(flowers)):

   print (flowers[index])

Output :

jasmine

Rose

Lilly

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

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.

  • python training
    Python Certification 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.


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

Call Now Button