ရိုးရိုးလေး ရှင်းပြမယ်
If...Else ကို ရိုးရိုးလေးနားလည်မယ်
if...else ကို condition တစ်ခုမှန်လား မမှန်လား စစ်ပြီး မတူညီတဲ့ code path ကို run ချင်တဲ့အခါ သုံးပါတယ်။ Login ဝင်ခွင့်ရှိလား၊ mark pass ဖြစ်လား၊ stock ရှိလား စတဲ့ decision logic တွေမှာ အမြဲတွေ့ရပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Broad condition ကိုအရင်ထားခြင်းနဲ့boundary တစ်ဖက်လွတ်ခြင်းက unreachable သို့misclassified branch ဖြစ်စေပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
`if` သည် boolean condition ကိုစစ်ပြီး branch တစ်ခုရွေးပါတယ်။ Conditions ကိုdomain rule အလိုက်အမည်ပေးထားသော booleans/methods ဖြင့်ရှင်းလင်းစေပြီး range boundaries, null guards နဲ့branch order ကိုစစ်ပါ။
- Typed input
- C# expression + method
- CLR value / object state
If...Else ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
int mark = 75;
if (mark >= 80)
{
Console.WriteLine("Distinction");
}
else if (mark >= 40)
{
Console.WriteLine("Pass");
}
else
{
Console.WriteLine("Fail");
}`if` သည် boolean condition ကိုစစ်ပြီး branch တစ်ခုရွေးပါတယ်။ Conditions ကိုdomain rule အလိုက်အမည်ပေးထားသော booleans/methods ဖြင့်ရှင်းလင်းစေပြီး range boundaries, null guards နဲ့branch order ကိုစစ်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Typed input
int mark = 75;if...else ကို condition တစ်ခုမှန်လား မမှန်လား စစ်ပြီး မတူညီတဲ့ code path ကို run ချင်တဲ့အခါ သုံးပါတယ်။ Login ဝင်ခွင့်ရှိလား၊ mark pass ဖြစ်လား၊ stock ရှိလား စတဲ့ decision logic တွေမှာ အမြဲတွေ့ရပါတယ်။
- C# expression + method
{`if` သည် boolean condition ကိုစစ်ပြီး branch တစ်ခုရွေးပါတယ်။ Conditions ကိုdomain rule အလိုက်အမည်ပေးထားသော booleans/methods ဖြင့်ရှင်းလင်းစေပြီး range boundaries, null guards နဲ့branch order ကိုစစ်ပါ။
- CLR value / object state
}Score grading rule ကိုexact boundary values 59, 60, 79, 80 နဲ့invalid range ဖြင့်table-driven စမ်းပါ။
- Typed input
- C# expression + method
- CLR value / object state
Success
If...Else ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Broad condition ကိုအရင်ထားခြင်းနဲ့boundary တစ်ဖက်လွတ်ခြင်းက unreachable သို့misclassified branch ဖြစ်စေပါတယ်။
if...else ကို condition တစ်ခုမှန်လား မမှန်လား စစ်ပြီး မတူညီတဲ့ code path ကို run ချင်တဲ့အခါ သုံးပါတယ်။ Login ဝင်ခွင့်ရှိလား၊ mark pass ဖြစ်လား၊ stock ရှိလား စတဲ့ decision logic တွေမှာ အမြဲတွေ့ရပါတယ်။
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ထဲကိုဝင်ပါတယ်။
PassInfo
💡 Practical use
User role စစ်တာ၊ payment status စစ်တာ၊ form input valid ဖြစ်မဖြစ်စစ်တာတွေမှာ if...else ကို မကြာခဏသုံးရပါတယ်။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Score grading rule ကိုexact boundary values 59, 60, 79, 80 နဲ့invalid range ဖြင့်table-driven စမ်းပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Score grading rule ကိုexact boundary values 59, 60, 79, 80 နဲ့invalid range ဖြင့်table-driven စမ်းပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
int mark = 75;
if (mark >= 80)
{
Console.WriteLine("Distinction");
}
else if (mark >= 40)
{
Console.WriteLine("Pass");
}
else
{
Console.WriteLine("Fail");
}ရလဒ်: If...Else ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Score grading rule ကိုexact boundary values 59, 60, 79, 80 နဲ့invalid range ဖြင့်table-driven စမ်းပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Typed input → C# expression + method → CLR value / object state
- `if` သည် boolean condition ကိုစစ်ပြီး branch တစ်ခုရွေးပါတယ်။ Conditions ကိုdomain rule အလိုက်အမည်ပေးထားသော booleans/methods ဖြင့်ရှင်းလင်းစေပြီး range boundaries, null guards နဲ့branch order ကိုစစ်ပါ။
- Broad condition ကိုအရင်ထားခြင်းနဲ့boundary တစ်ဖက်လွတ်ခြင်းက unreachable သို့misclassified branch ဖြစ်စေပါတယ်။
- Score grading rule ကိုexact boundary values 59, 60, 79, 80 နဲ့invalid range ဖြင့်table-driven စမ်းပါ။
C# documentation — Microsoft Learn