3.1.3 Conditionals

Two types of conditionals exist in Scilab: the if-then-else conditional and the select-case conditional. The if-then-else conditional evaluates an expression and if true executes the instructions between the then statement and the else statement (or end statement). If false the statements between the else and the end statement are executed. The else is not required. The elseif has the usual meaning and is a also a keyword recognized by the interpreter.
 
--> x=1
 x         =
 
    1.  
 
--> if x>0 then,y=-x,else,y=x,end
 y         =
 
  - 1.  
 
--> x=-1
 x         =
 
  - 1.  
 
--> if x>0 then,y=-x,else,y=x,end
 y         =
 
  - 1.

The select-case conditional compares an expression to several possible expressions and performs the instructions following the first case which equals the initial expression.

 
--> x=-1
 x         =
 
  - 1.  
 
--> select x,case 1,y=x+5,case -1,y=sqrt(x),end
 y         =
 
    i
It is possible to include an else statement for the condition where none of the cases are satisfied.