? IF-GOTO accepts multiple statements on single line (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

IF-GOTO accepts multiple statements on single line

  • #1 ✎ 906 snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself You 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. Posted
  • #2 ✎ 1619 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself But 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" Posted Edited by 12Me21