The problem with SuperBASIC is, that it doesn't have an "ELSE IF" (compound) statement, like other languages (e. g. C), but just an ELSE. So you normally should write it so:
Code: Select all
IF a$="first"
PRINT 1
ELSE
IF a$="second"
PRINT 2
ELSE
PRINT -1
END IF
END IF
REMark Above is explicit form, you may abbreviate it to:
IF a$="first":REMark 1st IF
PRINT 1
ELSE IF a$="second":REMark 2nd IF
PRINT 2
ELSE
PRINT -1
END IF: END IF:REMark END IFs must match the no of IFs above
This is indeed a shortage of SuperBASIC, I don't know if this (ELSE IF compound statement) was added for SBASIC.
Well, if one isn't afraid of using GOTO (there is a good reason why even modern languages like C++, Java C# have it!), one could use:
Code: Select all
100 IF a$="first"
110 PRINT 1:GO TO 1000:END IF
120 IF a$="second"
130 PRINT 2:GO TO 1000:END IF
140 REMark Add other clauses before line 999
999 PRINT -1
1000
Such a use of GO TO (all go to the same line number) is IMO acceptable, because of the shortage of SuperBASIC. In C (Java, C#) you need a GOTO, if you want jump out of a nested loop to an outer loop, which isn't required (NOT ACCEPTABLE) in SuperBASIC, as all loops have a name and you can use "EXIT loopname".
On Minerva (and afaik with Turbo) there is often a better solution (afaik): You can use SELect ON with integer and string variables, unfortunately this is not possible with SBASIC.