04-12-2003, 10:52 PM
04-12-2003, 11:40 PM
(RTFM stuff, blah blah, and such)
IF/THEN/ELSE/ENDIF is used this way:
IF/THEN/ELSE/ENDIF is used this way:
Code:
IF <condition> THEN
<instructions if YES>
ELSE
<instructions if NO>
END IF
04-13-2003, 02:35 AM
But don't forget our handy FM online:
http://qbasicnews.com/qboho/qckif.shtml
and
http://qbasicnews.com/qboho/qckadvr.ifx.shtml
http://qbasicnews.com/qboho/qckif.shtml
and
http://qbasicnews.com/qboho/qckadvr.ifx.shtml
04-13-2003, 02:57 AM
my program continues to tell me "Else without if". here's the program maybe you can fix it better than i would understand.[/code]
input "Do you want to play a math game"; reply$
if reply$ = yes then goto blahblahblah
if reply$ = no then print "O.K.": end
else end
input "Do you want to play a math game"; reply$
if reply$ = yes then goto blahblahblah
if reply$ = no then print "O.K.": end
else end
04-13-2003, 03:07 AM
Quote:my program continues to tell me "Else without if". here's the program maybe you can fix it better than i would understand.[/code]
input "Do you want to play a math game"; reply$
if reply$ = yes then goto blahblahblah
if reply$ = no then print "O.K.": end
else end
Code:
input "Do you want to play a math game"; reply$
if reply$ = yes then
goto blahblahblah:
end if
if reply$ = no then
print "O.K."
end
else
end
end if
04-13-2003, 06:42 AM
Better yet,
Code:
input "Do you want to play a math game"; reply$
if reply$ = "yes" then
goto blahblahblah:
elseif reply$ = "no" then
print "O.K."
end
else
end
end if
04-13-2003, 07:15 AM
Better still:
Try to avoid the evil Elseif. My first solution was showing it with a block-if, which was in answer to your question. This is the superior solution.
Code:
input "Do you want to play a math game"; reply$
select case ucase$(reply$)
case "YES"
goto blahblahblah:
case "NO"
print "O.K."
case else
end
end select
Try to avoid the evil Elseif. My first solution was showing it with a block-if, which was in answer to your question. This is the superior solution.
04-13-2003, 08:51 AM
and just why exactly is "elseif" evil?
04-13-2003, 08:54 AM
i'm not really sure. i use if. select -> end select is certainly a faster way, but it's so insignificant it would matter unless you were pulling this off thousand of times a second.
04-13-2003, 09:06 AM
ELSEIF is just this:
translates to... (faster to write)
I don't see why it is evil, but there is a better form, just like toonski said:
You'll only notice the speed increase if, as toonki said, you need to evaluate things in a long loop (for example, in a game loop).
Code:
IF a% = 3 THEN
PRINT "Three"
ELSE
IF a%=5 THEN
PRINT "Five"
ELSE
PRINT "Not five nor three"
END IF
END IF
translates to... (faster to write)
Code:
IF a%=3 THEN
PRINT "Three"
ELSEIF a%=5 THEN
PRINT "Five"
ELSE
PRINT "Not five nor three"
END IF
I don't see why it is evil, but there is a better form, just like toonski said:
Code:
SELECT CASE a%
CASE 3:
PRINT "Three"
CASE 5:
PRINT "Five"
CASE ELSE:
PRINT "Not five nor three"
END SELECT
You'll only notice the speed increase if, as toonki said, you need to evaluate things in a long loop (for example, in a game loop).