Thuta Learning
ရှာဖွေရန်
IntermediateProgrammingbeginner

If Statements

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

if statement က condition ပေါ်မူတည်ပြီး ဘယ် code block ကို run မလဲဆုံးဖြတ်ပေးပါတယ်။ Login success/fail, score grade, user role permission, form validation စတဲ့နေရာတွေမှာအရေးကြီးပါတယ်။

swift
let score = 82

if score >= 90 {
    print("Grade A")
} else if score >= 75 {
    print("Grade B")
} else if score >= 60 {
    print("Grade C")
} else {
    print("Try again")
}

Swift က condition တွေကို အပေါ်ကနေအောက်ကိုစစ်ပါတယ်။ score >= 90 မမှန်လို့ နောက် condition ကိုဆက်စစ်ပြီး score >= 75 မှန်တာကြောင့် Grade B ထုတ်ပါတယ်။

You should see
Grade B

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • if score = 90 က assignment ဖြစ်လို့မှားပါတယ်။ Comparison လုပ်ချင်ရင် == ကိုသုံးပါ။
If Statements | Thuta Learning