ရိုးရိုးလေး ရှင်းပြမယ်
If Statements ကို ရိုးရိုးလေးနားလည်မယ်
if statement က condition ပေါ်မူတည်ပြီး ဘယ် code block ကို run မလဲဆုံးဖြတ်ပေးပါတယ်။ Login success/fail, score grade, user role permission, form validation စတဲ့နေရာတွေမှာအရေးကြီးပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
if score = 90 က assignment ဖြစ်လို့မှားပါတယ်။ Comparison လုပ်ချင်ရင် == ကိုသုံးပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
If Statements မှာinput domain, exhaustive paths, return value, side effects နဲ့failure/cancellation behavior ကိုရှင်းပါ။ Force unwrap နဲ့silent error suppression မသုံးဘဲguard, typed errors နဲ့explicit propagation ကိုဦးစားပေးပါ။
- Typed value
- Swift expression / function
- Safe result
If Statements ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
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")
}If Statements မှာinput domain, exhaustive paths, return value, side effects နဲ့failure/cancellation behavior ကိုရှင်းပါ။ Force unwrap နဲ့silent error suppression မသုံးဘဲguard, typed errors နဲ့explicit propagation ကိုဦးစားပေးပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Typed value
let score = 82if statement က condition ပေါ်မူတည်ပြီး ဘယ် code block ကို run မလဲဆုံးဖြတ်ပေးပါတယ်။ Login success/fail, score grade, user role permission, form validation စတဲ့နေရာတွေမှာအရေးကြီးပါတယ်။
- Swift expression / function
} else if score >= 60 {If Statements မှာinput domain, exhaustive paths, return value, side effects နဲ့failure/cancellation behavior ကိုရှင်းပါ။ Force unwrap နဲ့silent error suppression မသုံးဘဲguard, typed errors နဲ့explicit propagation ကိုဦးစားပေးပါ။
- Safe result
}If Statements example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Typed value
- Swift expression / function
- Safe result
Success
If Statements ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
if score = 90 က assignment ဖြစ်လို့မှားပါတယ်။ Comparison လုပ်ချင်ရင် == ကိုသုံးပါ။
if statement က condition ပေါ်မူတည်ပြီး ဘယ် code block ကို run မလဲဆုံးဖြတ်ပေးပါတယ်။ Login success/fail, score grade, user role permission, form validation စတဲ့နေရာတွေမှာအရေးကြီးပါတယ်။
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 ထုတ်ပါတယ်။
Grade BReal-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
If Statements example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
If Statements example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
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")
}ရလဒ်: If Statements ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
If Statements example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Typed value → Swift expression / function → Safe result
- If Statements မှာinput domain, exhaustive paths, return value, side effects နဲ့failure/cancellation behavior ကိုရှင်းပါ။ Force unwrap နဲ့silent error suppression မသုံးဘဲguard, typed errors နဲ့explicit propagation ကိုဦးစားပေးပါ။
- if score = 90 က assignment ဖြစ်လို့မှားပါတယ်။ Comparison လုပ်ချင်ရင် == ကိုသုံးပါ။
- If Statements example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
The Swift Programming Language — Swift.org