Conditional Statements
Use haddii and kale for conditional branches, and dooro and xaalad for switch statements.
Conditional Statements
Conditional statements choose which block to execute based on a condition or value.
If Statements – haddii and kale
haddii starts an if statement. Use kale (condition) for else if and kale without a condition for else.
abn da = 17 haddii (da >= 18) { qor("Waad qaan gaadhay") } kale (da >= 13) { qor("Waxaad tahay dhallinyaro") } kale { qor("Waad yar tahay") }
Enclose each block in {}. You can chain conditional branches or nest them inside other blocks.
Boolean Conditions
Use boolean expressions and the operators &&, ||, and ! to write conditions.
abn x = 4 abn y = 9 haddii (x < y && y < 10) { qor("Shuruudaha waa sax") } // Negation haddii (!(x == y)) { qor("Qiimuhu ma sina") }
Summary
| Keyword | Meaning |
|---|---|
haddii | if |
kale | else if |
kale | else |
Switch-Case – dooro and xaalad
Use dooro to select a branch based on one expression. Each xaalad defines a case, and an optional kale defines the default branch.
qoraal maalinta = "Jimce" dooro (maalinta) { xaalad "Isniin" { qor("Todobaad cusub") } xaalad "Jimce" { qor("Waqti nasasho") } kale { qor("Maalin kale") } }
Switch statements are useful when several branches depend on the same value.
xaalad supports both numbers and strings. Only the matching case executes; there is no fall-through, so jooji is unnecessary. The default kale branch is optional.
abn lambar = 2 dooro (lambar) { xaalad 1 { qor("Hal") } xaalad 2 { qor("Laba") } xaalad 3 { qor("Saddex") } }
Combined Usage
You can combine haddii/kale branches with dooro statements to express more complex decisions.