On 19/06/2020 20:02, Daniel Baum via Ql-Users wrote:
What about doing something like this. In languages like c# the equivalent
of the "select on: command is hardly ever used and if .. else if ... else
is much more common:

100 INPUT a$
110 IF a$="a" THEN
115   PRINT "hello a"
120   ELSE
130     IF a$="b"
135     PRINT "hello b"
150     ELSE
155       IF a$="c"
157       PRINT "hello c "
160       ELSE
170         PRINT "hello d"
180       END IF
190     END IF
200 END IF

Actually, I had need of a similar construct recently. This is what I came up with:

100 FOR i% = 1 TO 6
110  case$ = 'case' & i%
120 c% = case$ INSTR "case1 case2 case3 case4 case5 case6"
130 :
140 SELect ON c%
150  =  1: PRINT 'case 1'
160  =  7: PRINT 'case 2'
170  = 13: PRINT 'case 3'
180  = 19: PRINT 'case 4'
190  = 25: PRINT 'case 5'
200  = 31: PRINT 'case 6'
210  = REMAINDER : PRINT 'ERROR'
220 END SELect
230 :
240 END FOR i%
This is obviously just a demo to illustrate the idea. It seems reasonably fast. In my case
I was able to keep all the terms to more or less the same size.
If there is a chance of ambiguity, one could wrap the terms in delimiters:

c% = '#' & case$ & '#' INSTR '#case1#test this2#or this#etc#..#'

Per


_______________________________________________
QL-Users Mailing List

Reply via email to