0

Issues with switch statement sintaxe

I'm running NINOX on a Mac.
Trying to understand the syntax of switch statment I wrote the following simple Switch which works fine on the console:

let Total := 0 ;

let x := [1, 2, 3, 4, 5] ;
for p in x do
    switch p do
        case 1:
            "Case 1 selected"
        case 2:
            "Case 2 selected"
        end
end ;

I get the following on the Output Panel which is ok:

"Case 1 selected"
"Case 2 selected"

I want to add more code to the case statments but then I get error messages and I do not understand why.

For instance if I add a simple line of code to case 2 like the following:

let Total := 0 ;

let x := [1, 2, 3, 4, 5] ;
for p in x do
    switch p do
        case 1:
            "Case 1 selected"
        case 2:
            "Case 2 selected"

            Total := Total + 2 ;
    end
end ;

I get an error message "symbol expected at line 10" (the new added line).

If I add a semicolon to the first line o case 2, I get the same error message, now for line 9.

 

What am I missing?

7 replies

null
    • Sviluppatore Ninox
    • Fabio
    • 2 yrs ago
    • Reported - view

    Hi Jose.

    The Ninox case construct for multiple code statements needs to be enclosed in parentheses.

    Try this:

    ---

    let Total := 0;
    let x := [1, 2, 3, 4, 5];
    for p in x do
       switch p do
       case 1:
          "Case 1 selected"
       case 2:
          (
             "Case 2 selected";
             Total := Total + 2
          )
       end
    end

    ---

       Fabio

    • JGM
    • Jose_Monteiro
    • 2 yrs ago
    • Reported - view

    Worked fine.

    Thanks for your help.

    • JGM
    • Jose_Monteiro
    • 2 yrs ago
    • Reported - view

    Looks like we just need the opening parenthesis.

    At least NINOX does not complain if we don't include the closing parenthesis.

    The following code worked fine:

    let x := [1, 2, 3, 4, 5] ;
    for p in x do
        switch p do
            case 1:
                (
                "Case 1 selected" ;
                "New Line Case 1"
            case 2:
                "Case 2 selected"
        end
    end

    • JGM
    • Jose_Monteiro
    • 2 yrs ago
    • Reported - view

    Well, it seems that not including the closing parenthesis doesn't always work.

    So it's best to follow Fabio's advice to enclose a block of code in parentheses.

    • Fred
    • 2 yrs ago
    • Reported - view

    Doesn't the app add the () for you? I also use the MacOS app and I've never had to add the () myself. When I click on OK and the go back in Ninox has added () for me.

    • JGM
    • Jose_Monteiro
    • 2 yrs ago
    • Reported - view

    I'm running Ninox version 3.5.8

    I tried to follow your suggestion but couldn't get the parentheses inserted automatically.
    By the way, if in a case you insert more than one command line without parentheses, Ninox immediately gives an error message.
    With error messages, clicking the OK button, nothing happens.
    The error has to be eliminated first in order to be able to close the window by clicking OK.
    Also on the console we don't have the OK button.

    • Fred
    • 2 yrs ago
    • Reported - view

    I just upgraded to 3.5.8 and this is what happens with me:

    Before:

    Screen Shot 2021-12-03 at 08.36.26

     

    After:

    Screen Shot 2021-12-03 at 08.36.42

Content aside

  • 2 yrs agoLast active
  • 7Replies
  • 456Views