Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: Français - Português - 日本語

Please note that the recommended version of Scilab is 6.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab help >> Scilab > Scilab keywords > if then else

if then else

conditional execution

Calling Sequence

if expr1 then statements
elseif expri then statements
else statements


The if statement evaluates a logical expression and executes a group of statements when the expression is true.

The expri are expressions with numeric or boolean values. If expri are matrix valued the condition is true only if all matrix entries are true or different from zero.

The optional elseif and else provide for the execution of alternate groups of statements. An end keyword, which matches the if, terminates the last group of statements. The line structure given above is not significant, the only constraint is that each then keyword must be on the same line as its corresponding if or elseif keyword.

The keyword then can be replaced by a carriage return or a comma.

Warning: the number of characters used to define the body of any conditionnal instruction (if while for or select/case) must be limited to 16k.


for j = 1:3, 
  if i == j then
    a(i,j) = 2; 
  elseif abs(i-j) == 1 then 
    a(i,j) = -1; 
  else a(i,j) = 0;

See Also

  • try — beginning of try block in try-catch control instruction
  • while — while keyword
  • select — select keyword
  • boolean — Scilab Objects, boolean variables and operators & | ~
  • end — end keyword
  • then — keyword in if-then-else
  • else — keyword in if-then-else
Scilab Enterprises
Copyright (c) 2011-2015 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu May 12 11:44:06 CEST 2011