Scilab Basics: Keyword variable Operators Loops functions

Scilab basic contains basics of Scilab language. you will familier with all basic terms of Scilab.

What is Scilab?

Scilab is free and open-source software for engineers & scientists. Scilab was developed with the Scilab team within the ESI Group.

It is a high-level numerical-oriented programming language.

Sci lab is used for Mathematics and Simulation, Optimization, Statistics Signal Processing,  Algorithm and application development, 2D and 3D data visualization, Image processing and Computer vision, in the field of IoT.

Scilab is an interpreted language. IT has a variety of functions to solve complex problems easily.

Scilab is available under the GPL License. It means any one can

Use the software for any purpose,

Change the software to suit your needs,

Share the software with your friends and neighbors, and

Share the changes you make.

Scilab Basics

it contains following topics

  1. Keyword
  2. Variables
  3. Constants
  5. Operators
  6. If else
  7. looping
  8. functions
  9. file creation in Scilab

Scilab keywords

Following are keywords in Scilab

  • backslash — (\) left matrix division.
  • brackets [,;] — Concatenation. Recipients of an assignment. Results of a function
  • colon (:) — Ranging operator. Addresses all elements along an array dimension or of a list.
  • comma — (,) comma; instruction, argument separator
  • comments — (// or /*…*/) comments
  • comparison — comparison, relational operators
  • dollar — ($) last index
  • dot — (.) symbol
  • equal — (=) assignment , comparison, equal sign
  • getscilabkeywords — returns a list with all scilab keywords.
  • hat — (^) exponentiation
  • greater — (>) greater than comparison
  • minus — (-) subtraction operator. Sign change
  • not — (~) logical not
  • parentheses — ( ) left and right parenthesis
  • percent — (%) special character
  • plus (+) — Numerical addition. Text concatenation (gluing)
  • quote — (‘) transpose operator, string delimiter
  • semicolon — (;) ending expression and row separator
  • slash — (/) right divisions. System’s feed back. Comments
  • star — (*) multiplication operator
  • symbols — scilab operator names
  • tilde — (~) logical not

Scilab variables 

In Scilab everything is the matrix. Scilab uses Boolean, string, integer, and complex numbers

Rules for Variable names

  • Variable names can take as long as you want.
  • Variable are case sensitive.
  • It allows characters (A-Z,a-z) digits(0-9) and special symbols(%,_,#,!,$,?).
  • First letter must be character or special character (%,_,#,!,$,?).
  • Multilingual UTF-8 characters are accepted.

Assigning value to variable

Scilab Constants

Sr No Constant Description
1 SCI, WSCI Variable containing the value of the root path of Scilab.
2 SCIHOME Contains the path to preferences, history files of your Scilab session.
3 TMPDIR Temporary directory path.
4 home Gives the user directory.
5 %e Euler number.
6 %eps epsilon (floating-point relative accuracy)
7 %f or %F Boolean variable for false.
8 %i imaginary unit
9 %inf infinity
10 %nan not-a-number
11 %pi ratio of circle’s circumference to its diameter
12 %s A variable used to define polynomials.
13 %t or %T Boolean variable for true.
14 %z A variable used to define polynomials.


To make single line comment // are used and to make multiline comment /*  and  */

are used.


// This is a single line comment

/* this is
Multiline comment*/

Basic Operators

Arithmetic Operators

Scilab has following arithmetic operators

Sr No Operator Example
1 + (Addition) 5+4=9
2 – (Substraction) 5-4=1
3 * (Multiplication) 5*4=9
4 / (Division) 4/2=2
5 ^ (Power) 2^3=8

relational operators in scilab

Scilab has following relational operators

Sr NoOperatorExample
1>5<6 (Less than)       T
2< (Greater than)6<7        F
3   <=  (Less than equals to)5<=6     T
4  >= (Greater than equals to)6>=7     F
5==   (Equals to)6==6     T
6~=  (Not Equals to)   or  <>7 ~=5     F

not equal scilab

The not equals in sci lab is mentiond as ~=  (Not Equals to)   or  <>

logical operators in scilab

Logical operator of scilab is as below

Sr No Operator Example
1 & (AND) %T & %F  F
2 |  (OR) %T |%F T
3 ~ (NOT) ~%T F

if else in scilab

In programming, we have to choose any one choice either this or that. in this case to choose one among two options we use if-else statement.

Syntax of if-else is as below

Let’s see one example to check the greater among two numbers


Using both if and else condition is Scilab

scilab if else example

scilab programs to check greater among two numbers


Select Statements

To select among multiple options scilab uses select statements

Syntax is select statement

Based on matching case expression statements are executed.

If no case expression is matched then else part is executed.

Here else is optional.

Example of case statement is as below


Looping Statements

Scilab supports for and while statements for looping

Syntax of for statment


How to perform a reverse loop in Scilab?


Use of break and continue

The break is used to end the looping statements.

Continue transfer the control to the beginning of the loop statement.

Example of break in Scilab

When break keyword is used in above program it break the loop and print value 1,2 and 3.


Example of continue in scilab

When continue occurs in the program it transfers the control to the beginning of the loop


  1. While  is a another looping keyword

Syntax is

while expr

Functions in Scilab

Function definition syntax

Scilab function to add two numbers.

Above is a function definition. To call sum function use sum(val1,val2) as below.

Scilab function to find the max of two numbers

How to create a file is Scilab

open a new file

write a basic statement

disp("Display from file")

Save file.

Press F5.

this will execute the command on the command window.

Read More