Log In  

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.

P#56111 2018-09-03 12:11 ( Edited 2018-09-03 21:47)

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.

P#56113 2018-09-03 13:01 ( Edited 2018-09-03 17:01)

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 ?

P#56120 2018-09-03 15:11 ( Edited 2018-09-03 19:12)

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
P#56123 2018-09-03 15:19 ( Edited 2018-09-03 19:19)

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"')
P#56138 2018-09-03 17:47 ( Edited 2018-09-03 21:47)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:52:23 | 0.007s | Q:17