Home  >  Article  >  Backend Development  >  How to write a program with infinite loop in python

How to write a program with infinite loop in python

尚
Original
2019-07-02 10:55:5711843browse

How to write a program with infinite loop in python

Infinite loop:

while condition is always true:

For example, while True:

(4 spaces) execute code

Loop termination statement:

break

is used to completely end a loop and jump out of the loop body to execute the statements following the loop.

continue

continue just terminates this loop and then executes the following loop, while break terminates the loop completely.

Example:

i = 0
while True:
  i = i + 1
  if i == 50:
     print 'I have got to the round 50th!'
     continue
  if i>70:break    #结束死循环
  print i

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to write a program with infinite 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