如果条件判断语句永远为 true,循环将会无限的执行下去,如下实例:
实例
#!/usr/bin/python # -*- coding: UTF-8 -*- var = 1 while var == 1 : # 该条件永远为true,循环将无限执行下去 num = raw_input("Enter a number :") print "You entered: ", num print "Good bye!"
以上实例输出结果:
代码语言:javascript复制Enter a number :20
You entered: 20
Enter a number :29
You entered: 29
Enter a number :3
You entered: 3
Enter a number between :Traceback (most recent call last):
File "test.py", line 5, in <module>
num = raw_input("Enter a number :")
KeyboardInterrupt
注意:以上的无限循环你可以使用 CTRL C 来中断循环。