
When using SELECT CASE conditional statements, in order to have a readable code, it is recommended to:Īs an example, we will write a script which displays in the Scilab console the corresponding decimal number (10 … 15) for a hexadecimal letter (A … F).

In the examples below we’ll use different types of syntax which will output the same result.

If the keyword then is not on the same line with the corresponding case, a continuation mark must be used. Note: The keyword then must be on the same line with the corresponding case keyword. If none of the cases are found TRUE then the else instructions are evaluated (default instructions). If controlVariable = value_2, the instructions_2 are executed. If controlVariable is different than value_1, the following value ( value_2) is used for comparison. When a match case is found, the corresponding instruction is executed.įor example, if controlVariable = value_1 the instructions_1 are executed. The current value of the control variable ( controlVariable) is evaluated and compared with each of the cases starting with the fist one ( value_1). The general syntax of the SELECT CASE conditional statement is:

If the control variable has multiple states, for a better structure and readability of the code, it is better to use SELECT CASE instead of IF ELSEIF conditional statements. When designing an algorithm we might come up with a situation in which we would like to define some actions function of the state/value of another variable.
