5

I am working on some old qbasic code. It's a mess with all the Goto statements. Am I correct that the following line will always return?

IF FLAG = 0 THEN TARGET = X: GOSUB 55000: TEMP = XI - TEMP2: RETURN 

So if I understand this correctly the colon separates statements on the same line. The if only pertains to TARGET = X. The GOSUB, TEMP =, and RETURN will always execute. Correct?

Part of my confusion is because the very next line reads

IF FLAG = 1 THEN STEP = X: GOSUB 115000

And since the label to the second statement is never used in a GOTO I can't see that it would ever get executed.

Seth Hays
  • 311
  • 2
  • 11

1 Answers1

5

Yes, I believe your assessment is correct. The colon is a statement separator that lets you have multiple statements on the same line. Assuming your subroutine at 55000 returns, this line should return as well.

I was wrong. Running this program:

if 1=2 then print "Never printed" : print "how about this?"
print "End of program"

on qb64.net prints only End of program. I assume that its grammar details are the same as Qbasic's, although it is a reverse-engineered effort.

As an aside, this code is written in a pre-QBasic style (e.g. using GOSUB and line numbers). There is a script that often came with QBasic (remline.bas, I believe it was called) that is supposed to help translate these kinds of programs to a newer style. I have never used it myself, though.

Troy
  • 1,599
  • 14
  • 28
  • Thanks. I must say the only thing worse than spaghetti code is poorly written spaghetti code. – Seth Hays Aug 08 '13 at 21:11
  • I found this link that seems to say my assumption is wrong. http://stackoverflow.com/questions/367325/vb-net-if-statement-and-the-colon – Seth Hays Aug 08 '13 at 23:24
  • Well, I just tested it at [qb64.net](http://qb64.net), which apparently has an online interface to their implementation now, and it turns out that I was wrong. Thanks for letting me know so I can edit my response :). – Troy Aug 08 '13 at 23:34
  • 2
    And just in case someone else comes across this, the code: if 1=2 then print "Never printed" : print "how about this?" : else print "this prints", will print "this prints". In other words, the else is still executed even after the colon. – Tom Collins Jan 29 '16 at 20:34