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

If...Else...Elseif

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

if, elseif, else ကို condition ပေါ်မူတည်ပြီး မတူတဲ့ code block တွေ run ဖို့သုံးပါတယ်။ ဥပမာ user login ဝင်ထားလား၊ stock ရှိလား၊ age ပြည့်လား၊ form မှန်လား စတာတွေ။

php
<?php
$score = 82;

if ($score >= 90) {
  echo "Grade A";
} elseif ($score >= 80) {
  echo "Grade B";
} elseif ($score >= 60) {
  echo "Grade C";
} else {
  echo "Try again. Practice is the real cheat code.";
}
?>
You should see
Grade B

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

  • Condition အစီအစဉ်မှားတာက logic bug ဖြစ်စေပြီး error မပြပေမယ့် result မှားနိုင်ပါတယ်။ ဒါက silent villain ပါ။
If...Else...Elseif | Thuta Learning