If Else in Scilab
Branching with if
and else
in Scilab is straightforward.
Note that in Scilab, you don’t need parentheses around conditions, but the then
keyword is required. The end
keyword is used to close the if
block.
To run this script, save it as if_else.sce
and execute it in Scilab:
There is no ternary operator in Scilab, so you’ll need to use a full if
statement even for basic conditions.
Scilab uses &
for logical AND and |
for logical OR, unlike some other languages that use &&
and ||
. Also, string concatenation in Scilab is done using the +
operator.
The modulo
function is used in place of the %
operator for remainder calculations. The disp
function is used for displaying output, similar to print
or console.log
in other languages.
Scilab’s elseif
is written as one word, unlike the else if
in some other languages.
These differences showcase some of the unique aspects of Scilab’s syntax and built-in functions compared to other programming languages.