ianatha / bababasic

QuickBASIC 4.5 revival on Android
https://play.google.com/store/apps/details?id=io.atha.quickbasic
MIT License
94 stars 4 forks source link

IF...THEN...ELSE blocks don't seem to work #102

Open byronpendason opened 7 months ago

byronpendason commented 7 months ago

My code:

PRINT "What is your name, adventurer?"
INPUT "> "; name$
PRINT "Greetings, "; name$; "!"
IF name$ = "Byron" THEN
    PRINT "Welcome, Byron, the greatest hero of all time!"
ELSE
    PRINT "Greetings, "; name$; ". Not the hero I was expecting, but I guess you'll do."
END IF

I get an error about no viable alternative, as shown in the screenshot provided. Screenshot_20240405-155352

byronpendason commented 7 months ago

As an update, I went through your examples and discovered that in order to use if block statements, you must use BEGIN after THEN and ELSE. The following modification of the above code works:

PRINT "What is your name, adventurer?"
INPUT "> "; name$
IF name$ = "Byron" THEN BEGIN
    PRINT "Welcome, Byron, greatest hero of all time!"
ELSE BEGIN
    PRINT "Greetings, "; name$; ". Not the hero I was expecting, but I guess you'll do."
END IF

So, while this makes sense, it's not QBasic compatible because QBasic lacks the BEGIN statement.