IF-GOTO accepts multiple statements on single line
#1✎ 943snail_HelperReceived for being very helpful around SmileBASIC SourceAchievementsOSP Contest 2 Contest ParticipantI participated in the second SmileBASIC Source OSP Contest!Night PersonI like the quiet night and sleep late.Express YourselfYou may know that with IF you can write multiple statements on one line to be run when the condition is true.
IF X%<0 THEN X%=0:?"Hit a wall"
You may also be aware of the IF-GOTO shorthand to jump to a label on a condition.
IF DEAD GOTO @GAMEOVER
But, did you know you can write multiple statements on an IF-GOTO?
IF DEAD GOTO @GAMEOVER:?"YOU DIED"
If you're thinking "well that code doesn't make any sense" that's because it doesn't. The GOTO immediately jumps away from, and thus entirely skips the remainder of the statement. The rest of that IF doesn't do anything; the text is never printed.
This is not a case where it just looks like the multiple statements are blocked together when they really aren't. Even if that condition were to fail, the PRINT would still never happen since it's lumped in with the IF.
There is no IF-GOSUB shorthand, where this sort of thing might make sense, so this should probably just be illegal syntax. I can only assume that if you write the IF-GOTO form the THEN is treated as implicit and inserted automatically, but this of course leads to this weird semantic inconsistency where doing it with GOSUB isn't allowed and you wind up writing code that never does anything. Yet another reason to avoid gotos.
#2✎ 169012Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfBut is this a bug though?
It looks like IF...GOTO is just short for IF ... THEN GOTO, so this makes sense.
EDIT: I just remembered that it is possible for the code after the GOTO to run:
IF X GOTO @IF:@IF:PRINT "HELLO"