1. 程式人生 > >Study 6 —— while循環

Study 6 —— while循環

style 條件 val 一次 ont 循環 div har size

語法
while 條件:
  執行代碼。。。

1. #從0打印到100,每循環一次 +1

count = 0

while count <= 100 :
print(‘Loop: ‘, count)
count += 1

2. #打印從1到100的偶數

count = 1

while count <= 100 :	
if count % 2 == 0 :
print(‘Even: ‘, count)
count += 1

3. #循環打印1-100,第50次不打印值,第60-80次打印對應值的平方

count = 1

while count <= 100:
if count == 50:
pass
elif count >= 60 and count <= 80:
print(‘Value: ‘, count ** 2)
else:
print(‘Value: ‘, count)	
count += 1

4. 死循環

count = 0
while True:
print(‘Value‘, count)
count += 1

  

Study 6 —— while循環