Home >Backend Development >Python Tutorial >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!