while循环
#第50次不打印,第60-80次打印对应值的平方
1 count = 0 2 3 while count <= 100: 4 if count == 50: 5 pass 6 elif count >= 60 and count <=80: 7 print(count*count) 8 else: 9 print("loop ",count) 10 11 count += 1 12 13 print("------loop is ended-------")
Dead Loop(死循环)
count = 0 while True:#True本身就是真 print("forever-------",count) count += 1
break 用于完全结束一个循环,跳出循环体执行魂环后面的语句 continue 只是终止本次循环,接着执行后面的循环
count = 0 while count <= 100: print("loop ",count) if count == 5: break count += 1 print("------out of loop-------")
count = 0 while count <= 100: print("loop ",count) if count == 5: continue count += 1 print("------out of loop-------")
0-100循环,跳过6到94
count = 0 while count <= 100: count += 1 if count > 5 and count < 95: continue print("loop ",count) print("------out of loop-------")