Hi,
I found a way to simulate
SELECT CASE in MY-BASIC without adding new keywords. Implemented as a
select function as follow, which accepts a variable argument list with a boolean expression, a lambda expression, another boolean expression, and another lambda... The advantage is it accepts not only one constant equivalence case condition, but also a boolean expression with more sub conditions for one case; the disadvantage is it requires a very ugly single line code calling the
select function. Maybe it's necessary to add multi-line code linking to MB now, just like what the underline _ does in VB.
default = true ' For the default case
def select(...)
l = len(...)
if l mod 2 <> 0 then
print "Parameters not matched.";
return
endif
for i = 0 to l - 1 step 2
if ... then ' Evaluates a condition
_ = ... ' Gets a lambda and executes it
_()
return
else
_ = ... ' Ignores a lambda argument
endif
next
enddef
a = 85
select(a >= 85, lambda () (print "A";), a >= 75, lambda () (print "B";), a >= 60, lambda () (print "C";), default, lambda () (print "D";))