Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.0.0 - Русский


select

ключевое слово выбора

Syntax

select variable
case value1 then
instructions 1
case value2 then
instructions 2
...
case valuen then
instructions n
case {valueC1 valueC2 valueCN}
intructions C
[else
instructions]
end

Аргументы

variable

переменная, значение которой анализируется.

value1, ..., valuen

значения переменной variable для которых предусмотрен соответствующий набор инструкций instructions 1, ..., instructions n.

valueC1, ..., valueCN

like value1, ..., valuen but an OR is applied on each variable == valueCx. It is useful to group cases with same instruction.

instructions

набор корректных инструкций.

Examples

function select_example(n)
    select n
    case 0 then
        disp(0)
    case 1 then
        disp(1)
    case {2 3}
        disp({2 3})
    else
        disp("default")
    end
endfunction

select_example(0); // 0
select_example(1); // 1
select_example(2); // {2 3}
select_example(3); // {2 3}
select_example(4); // "default"

Смотрите также

  • if — ключевое слово для условного выполнения
  • while — ключевое слово while
  • for — ключевое слово для циклов

История

ВерсияОписание
6.0.0
  • select is now protected: Assignments like select=1 are no longer possible.
  • The number of characters used to define the body of any conditional instruction (if, while, for, or select/case) is no more limited to 16k.
2024.0
  • Add grouped case with cell representation case {2 3} to match either 2 or 3
Report an issue
<< return Управляющая логика then >>

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:
Tue Oct 24 14:37:04 CEST 2023