Python loop statement


  Translation results:

Programming languages ​​provide various control structures that allow for more complex execution paths. Loop statements allow us to execute a statement or group of statements multiple times

Python loop statementsyntax

Python provides for loops and while loops (there is no do..while loop in Python)

Python loop statementexample

while loop statement
#!/usr/bin/python
count = 0while (count < 9): print 'The count is:', count
count = count + 1
print "Good bye!"
for loop statement
#!/usr/ bin/python# -*- coding: UTF-8 -*-
for letter in 'Python': # first instance
print 'Current letter:', letter
fruits = ['banana', 'apple', 'mango']for fruit in fruits: # The second example
print 'Current fruit:', fruit
print "Good bye!"

Popular Recommendations

Home

Videos

Q&A