Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.1.0 - English


while

Opens a block of instructions iterated on a heading condition

Syntax

while expr, instructions,..., end
while expr do instructions,..., end
while expr then instructions,..., end

Description

The while clause must be terminated by "end".

Notes:

  • The only constraint is that each then or do keyword must be on the same 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.

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
    disp(i);
    i = i + 1;
end

rather than

i = 0; while i<5, disp(i), i = i + 1; end
The number of characters used to define the body of any conditional instruction (if while for or select/case) must be limited to 16k.

Examples

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

See also

  • |, || — Binary OR between integers. Logical OR over/between booleans and numbers
  • &, && — Binary AND between integers. Logical AND over/between booleans and numbers
  • break — keyword to interrupt loops
  • for — keyword entering a non-conditional loop
  • select — select keyword

History

VersionDescription
6.0.0
  • The [,else instructions] syntax is no longer supported.
  • while is now protected: Assignments like while=1 are no longer possible.
Report an issue
<< try Control flow Configuration >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon May 22 12:37:04 CEST 2023