Home>Article>Backend Development> How to implement infinite loop in python

How to implement infinite loop in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼 Original
2019-06-13 14:48:05 29790browse

How to implement infinite loop in Python? Loop statements in Python include for and while. Infinite loop statements can be constructed in two ways: for and while.

How to implement infinite loop in python

The control structure diagram of Python loop statement is as follows:

How to implement infinite loop in python
Related recommendations: "python video tutorial

while loop

var = 1 while var == 1 : # 该条件永远为true,循环将无限执行下去 num = raw_input("Enter a number :") print "You entered: ", num print "Good bye!"

for loop

class Infinit: def __iter__(self): return self def __next__(self): return None for i in Infinit(): print("好嗨哟,你是不是学会了Python的无限循环!") print("我是永远不会执行到的")

The above is the detailed content of How to implement 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
Previous article:Is python open source? Next article:Is python open source?