Soplang Logo
Soplang

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.

if_statements.sop
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.

boolean_conditions.sop
abn x = 4
abn y = 9

haddii (x < y && y < 10) {
  qor("Shuruudaha waa sax")
}

// Negation
haddii (!(x == y)) {
  qor("Qiimuhu ma sina")
}

Summary

KeywordMeaning
haddiiif
kaleelse if
kaleelse

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.

switch_case.sop
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.

switch_numbers.sop
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.

On this page