ရိုးရိုးလေး ရှင်းပြမယ်
Python for loop သည် sequence သို့မဟုတ် iterable ၏ item များကိုအစဉ်လိုက်လည်ပတ်သည်။ အကြိမ်ရေသတ်မှတ်လိုပါက range() သုံးပြီး condition မှန်နေသရွေ့လုပ်လိုပါက while သုံးသည်။ break က loop ကိုရပ်ပြီး continue က လက်ရှိအကြိမ်ကိုကျော်သွားသည်။
python
scores = [68, 42, 91, 77]
for index, score in enumerate(scores, start=1):
if score < 50:
continue
print(f"{index}: {score}")
attempts = 3
while attempts > 0:
print(f"Attempts left: {attempts}")
attempts -= 1You should see
1: 68
3: 91
4: 77
Attempts left: 3
Attempts left: 2
Attempts left: 1လက်တွေ့စမ်းကြည့်ရန်
1 မှ 30 အတွင်း 3 ဖြင့်စားပြတ်သော် Fizz၊ 5 ဖြင့်စားပြတ်သော် Buzz ထုတ်သော loop ရေးပါ။
Python Control Flow — Python Software Foundation