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

Change language to:
Français - 日本語 - Português - Русский

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

Scilab Help >> Scilab > Control flow > select

select

select keyword

Syntax

select variable
case value1 then
instructions 1
case value2 then
instructions 2
...
case valuen then
instructions n
[else instructions]
end

Arguments

variable

variable which value to be analyzed.

value1, ..., valuen

values of variable for which there are appropriate instruction blocks instructions 1, ..., instructions n.

instructions

block of valid instructions.

Description

Notes:

  • The only constraint is that each then keyword must be on the same line as corresponding case keyword (or use a continuation mark, see dot).

  • The keyword "then" can be replaced by a carriage return or a comma. instructions1 are executed if expr1=expr, etc.

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:

A = 2
select A
case 1 then
    disp(1)
case 2 then
    disp(2)
else
    disp(3)
end

rather than

A = 2;select A case 1 then disp(1); case 2 then disp(2); else  disp(3); 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.

Examples

while %t do
    n=round(10*rand(1,1))
    select n
        case 0 then
        disp(0)
    case 1 then
        disp(1)
    else
        break
    end
end

See also

  • if — keyword for conditional execution
  • while — Opens a block of instructions iterated on a heading condition
  • for — keyword entering a non-conditional loop

History

VersionDescription
6.0.0 select is now protected: Assignments like select=1 are no longer possible.
Report an issue
<< return Control flow then >>

Copyright (c) 2022-2024 (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:
Tue Feb 25 08:49:18 CET 2020