Hello:
- I was wondering if there was a way to use something like select case:
SELECT CASE A 2: PRINT"TWO" 3: PRINT"THREE" END or ... IF (A==2,3,4,5) PRINT"GREATER THAN 1 AND LESS THAN 6." |
Something, which will meet multiple conditions for one or more variables.
switch/case: plain if/elseif or functional programming:
function nop() end ({[2]=function() print(“2”) end, [3]=function() print(“3”) end}[a] or nop)() |
for the other question, seriously, this is lua for pico - not going to do any complex data manipulation with it.
Omy, wow. Thanks, Fred. Need to sit down and take a good look at what you wrote here.
Hmm ... that's not any less coding than:
if (nop==2) print"2" if (nop==3) print"3" |
That's what I was looking for, a short-cut to compare the same variables many times and to do different actions based upon the results.
Or am I not understanding the code correctly ?
Suggest to stick with if/elseif and: https://www.lua.org/pil/1.html
if a==2 then print"2" elseif a==2 then print"3" end |
Yeah, trying to avoid both. Was hoping there was an easier way. It would be useful to have a command like:
COMMAND (string) |
Where (string) is any command or inquiry like:
"if a==2 then print"2" elseif a==3 then print"3" end |
"
That could be converted from an intelligent function:
IFMULTI('a,=2,print"2",=3,print"3"') |
[Please log in to post a comment]