annoying problem - or I don't get it
- Posted by jessedavis Jun 17, 2010
- 1086 views
The switch statement requires a constant to test against in each case statement. It works great; however, if one has a lot of tests to do where the case tests a are computed at runtime there is a problem. So>
constant tests = {3,9,12,33} --really a much longer sequence integer x = 12 switch x do case tests[1] then puts(1,"Case = 1\n") break case "" end switch
output follows:
jd@jd-ubuntu:~/euphoria/code/misc_and_test$ eui switch_test.ex switch_test.ex:4 <0066>:: expected 'then' or ',', not '[' case tests[1] then ^
As you can see the parser cannot handle what is otherwise a perfectly valid statement. tests[1] is a constant. Try creating a bunch of constants one at a time. I know there are other ways of doing this - some are even elegant. I just think it should work!
Regards, jd
any thoughts? anyone?