Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account

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

Scilab help >> Scilab > Control flow > while


while keyword


The while clause must be terminated by "end".

while expr ,instructions,...[,else instructions], end

while expr do instructions,...[,else instructions], end

while expr then instructions,...[,else instructions], end


  • The only constraint is that each then or do keyword must be on the same line line as while keyword.

  • Keywords then or do can be replaced by a carriage return or a comma. For compatibility with Matlab it is also possible, but not recommended, to put a space between the end of the expression and the beginning of the first instruction.

  • The optional [,else instructions] construction allows to gives instructions which are executed when expr expression becomes false.

According to the Code Conventions for the Scilab Programming Language it is recommended:

  • Start each statement on a new line.

  • Write no more than one simple statement per line.

  • Break compound statements over multiple lines.

For example, use:

i = 0
while i<5 
    i = i + 1; 

rather than

i = 0; while i<5 disp("i"); i = i + 1; end

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


e=1; a=1; k=1;
while norm(a-(a+e),1) > %eps, 

See Also

  • for — language keyword for loops
  • select — select keyword
  • break — keyword to interrupt loops
  • return — return or resume execution and copy some local variables
  • pause — pause mode, invoke keyboard


Add a comment:
Please login to comment this page.

Report an issue
<< then Control flow Configuration >>

Scilab Enterprises
Copyright (c) 2011-2014 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Apr 02 17:36:20 CEST 2013