How to write a program with infinite loop in python

Release: 2019-07-06 09:01:18
Original
11842 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!