The Sababa Programming Language

If Statements

An if-statement runs a block of code only if a certain condition is met, often a boolean value as we've seen in previous chapters. In Sababa it's possible to run an if-else statement in one line. The format for an if-else statement is as follows:

  • if(cond){do_this}{else_do_this}

Basically if a condition the symbolic expression "()" is met, execute the first quoted expression "{}", else execute the code in the second quoted expression. It works similarly to ternary operators in some languages. An example in Sababa is:

sababa> def{x y} 200 300

=> ()

sababa> if (== x y) {+ x y} {- x y}

=> -100

Since x which is 200, and y which is 300 aren't equal to each other, we run the code in the second quoted expression, which would be equivalent to an else statement in a different language. We see that x - y or 200 - 300 indeed equals -100.