python 循环 while

格式
while 判断条件
    执行语句

whiler执行时,如果判断条件为True,执行while中的语句,完成后不跳出while,继续执行判断,只有当判断条件返回为False时,才会跳出while循环,执行后面的代码

如果第一次判断为Fales,则不进入while循环,直接执行后面的代码

num = 0
while num <= 5:
    print(num)
    num += 1
print('end')

执行:
C:\Python27\python.exe D:/Python/type-of-data.py
0
1
2
3
4
5
end

Process finished with exit code 0

########################################################

num = 0
while num > 5:
    print(num)
    num += 1
print('end')

执行:
C:\Python27\python.exe D:/Python/type-of-data.py
end

Process finished with exit code 0
############################################################
当

while 1: 
    pass
    
# 判断条件永远为True,将会一直执行pass内的代码
#############################################################
        

相关文章:

  • 2021-12-15
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-08-14
  • 2021-11-06
  • 2021-09-15
  • 2021-05-26
  • 2021-11-08
相关资源
相似解决方案