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
-
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
-
Worked fine.
Thanks for your help.
-
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
-
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.
-
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.
-
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. -
I just upgraded to 3.5.8 and this is what happens with me:
Before:
After:
Content aside
- 3 yrs agoLast active
- 7Replies
- 464Views