Home  >  Article  >  Backend Development  >  How to use while loop in python

How to use while loop in python

巴扎黑
巴扎黑Original
2017-08-15 13:37:453071browse

This article mainly introduces the usage of the while loop statement in python, and analyzes the use of the while statement with examples. Friends in need can refer to it

The examples in this article describe the usage of the while loop statement in python. Share it with everyone for your reference. The specific analysis is as follows:

For python’s while statement, just pay attention to its indentation. Python, like other languages, also has break and continue, which are used to indicate jumping out of the loop and continuing the loop respectively.


#!/usr/bin/python
# Simple while loop
a = 0
while a < 15:
  print a, # 在print a后面加,不换行
  if a == 10:
    print "made it to ten!!"
  a = a + 1

The running results are as follows:

0 1 2 3 4 5 6 7 8 9 10 made it to ten!!
11 12 13 14

The above is the detailed content of How to use while loop in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn