Thuta Learning
C#
BasicProgrammingbeginner

If...Else

if...else ကို condition တစ်ခုမှန်လား မမှန်လား စစ်ပြီး မတူညီတဲ့ code path ကို run ချင်တဲ့အခါ သုံးပါတယ်။ Login ဝင်ခွင့်ရှိလား၊ mark pass ဖြစ်လား၊ stock ရှိလား စတဲ့ decision logic တွေမှာ အမြဲတွေ့ရပါတယ်။

csharp
int mark = 75;

if (mark >= 80)
{
    Console.WriteLine("Distinction");
}
else if (mark >= 40)
{
    Console.WriteLine("Pass");
}
else
{
    Console.WriteLine("Fail");
}

Condition flow

  • အရင်ဆုံး mark >= 80 ကိုစစ်ပါတယ်။ မမှန်လို့နောက်ထပ် condition ဆက်စစ်ပါတယ်။
  • mark >= 40 ကမှန်တဲ့အတွက် Pass ကို output ထုတ်ပါတယ်။
  • အပေါ်က condition တွေအားလုံး မမှန်မှ else ထဲကိုဝင်ပါတယ်။
You should see
Pass

Info

💡 Practical use

User role စစ်တာ၊ payment status စစ်တာ၊ form input valid ဖြစ်မဖြစ်စစ်တာတွေမှာ if...else ကို မကြာခဏသုံးရပါတယ်။

If...Else | Thuta Learning