Goto main content

help desk

How to use a swicth statement in SnCode

Is there a function in SnCode I could use to switch statement?

Asked on 2020-03-26 08:35:00

OFFICIAL ANSWER

A new switch statement has been added to Sncode version 5.132. The general syntaxt for the switch statement is:

switch(expression1) do
    case expression2: 
        statement;
    endc
    casere:ixsm expression3:
        ...
    endc
    ...
    default:
         statement;
    endc
ends
 

If expression1 is a string than each case is string compare and the matching one is executed. Only one is executed.
So expression1 eq expression2 is executed.

If expression1 is a number that each case is compare as a number and the matching one is executed.
So expression1 == expression2 is executed.

In the case of casere if expression1 is a string than expression is match against regular expression in expression3.
If expression1 is a number and a normal number compare is performed. The flag i for ignore case, 
x for extensed regular expression, m for multiline regular expression and s for "dot match all".

 

Answer by:
Pierre Laplante

Replied on: 2020-03-26 12:32:00