10 月 102020
#Python中的两种循环:for循环和while循环
#for循环在可迭代的序列被穷尽时停止
#while循环在条件不成立时停止,即只要……条件成立,就一直做……
while 1 < 3:
print('1 is smaller than 3')
#永远为True的循环,称之为死循环,Ctrl+C强制停止运行
#赋值变量,计数目的,初始值为0
count = 0
#while循环
while True:
print('Repeat this line!')
count = count + 1 #每打印一行,对count加1并重新赋值给count
if count == 5: #判断count当前是否为5,是则终止while循环
break #关键词
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe c:/Users/harveymei/hello.py
Repeat this line!
Repeat this line!
Repeat this line!
Repeat this line!
Repeat this line!
PS C:\Users\harveymei>