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

If / Else

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

if, else if, else ကို condition အပေါ်မူတည်ပြီး code path ခွဲရန်သုံးပါတယ်။ Login status, form validation, pricing rule, user role permission စတာတွေမှာအမြဲတွေ့ရပါတယ်။

dart
void main() {
  int score = 82;

  if (score >= 90) {
    print('Grade A');
  } else if (score >= 80) {
    print('Grade B');
  } else if (score >= 60) {
    print('Grade C');
  } else {
    print('Try again with a better study plan.');
  }
}

Dart က condition တွေကို အပေါ်ကနေ အောက်ကိုစစ်ပါတယ်။ score >= 80 မှန်သွားတာနဲ့ Grade B ကိုထုတ်ပြီး နောက်ထပ် condition တွေကိုမစစ်တော့ပါ။

You should see
Grade B

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

  • Condition order မှားရင် result မှားနိုင်ပါတယ်။ ဥပမာ score >= 60 ကို အပေါ်ဆုံးထားရင် 90 ရတဲ့သူတောင် Grade C ဖြစ်သွားနိုင်ပါတယ်။
If / Else | Thuta Learning