Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with ELSE
#1
I am having trouble using else in my program.
How can i use else in my program to stop invalid entries.
Reply
#2
(RTFM stuff, blah blah, and such)

IF/THEN/ELSE/ENDIF is used this way:

Code:
IF <condition> THEN
   <instructions if YES>
ELSE
   <instructions if NO>
END IF
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
But don't forget our handy FM online:

http://qbasicnews.com/qboho/qckif.shtml
and
http://qbasicnews.com/qboho/qckadvr.ifx.shtml
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#4
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
Reply
#5
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
Reply
#6
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
Reply
#7
Better still:

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.
Reply
#8
and just why exactly is "elseif" evil?
Reply
#9
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.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#10
ELSEIF is just this:

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).
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)