I want to know how you add a if/then command. I want it so if you type in 'read me' on the input it would jump somewhere (like a GOTO), and if you type 'play' it would jump somewhere else, and if you type 'about' it will jump another place, and so on. I can't quite find out how to do this.
I am using a program called Just BASIC if that helps.
THANK YOU SO MUCH!
10
Input "Enter a key-word: ", KeyWord$
If lcase$(KeyWord$) = "read me" then
Goto ReadMe:
Elseif lcase$(KeyWord$) = "play" then
Goto PlayMe:
Elseif lcase$(KeyWord$) = "about" then
Goto About:
Else
Goto 10
End if
But For something like this I suggest using a Case Select statement
10
Input "Enter a key-word: ", KeyWord$
Select Case lcase$(KeyWord$)
Case "read me"
Goto ReadMe:
Case "play"
Goto PlayMe:
Case "about"
Goto About:
Case Else
Goto 10
End Select
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer
True most prefer and suggest the use of subs. I just use Goto in examples. I don't know why. That and it was asked for. Oh well.
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer
Somehow funny. Others thinks that GOTO is for bad...me, i dont think that way. I use gGOTO if it?s usable...dont wana waste my time for thinking other ways...
Dont' get me wrong, Goto is a great thing. But not all the time, subs are great, but not all the time.
In the case of if they enter something other than one of the main options it should GOTO the input question again. However the selected option should have it's own space.
I suggest using both not one or the other.
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer
Even in that case I wouldn't use GOTO. Any time I've used an input expecting certain options, I use a loop, where the options typed that are expected open a sub, returning control to the loop when the subs end.
GOTO isn't necessarily a bad thing, I agree, and can be very useful in many situations, but I just kind of shied away from it after awhile.
vohaul wrote:Even in that case I wouldn't use GOTO. Any time I've used an input expecting certain options, I use a loop, where the options typed that are expected open a sub, returning control to the loop when the subs end.
GOTO isn't necessarily a bad thing, I agree, and can be very useful in many situations, but I just kind of shied away from it after awhile.
DO
Input "Enter a key-word: ", KeyWord$
If lcase$(KeyWord$) = "read me" then
Goto ReadMe:
Elseif lcase$(KeyWord$) = "play" then
Goto PlayMe:
Elseif lcase$(KeyWord$) = "about" then
Goto About:
Else
LOOP Until KeyWord$ = "Q" or KeyWord$ = "q"
End if
Here i would use DO...LOOP instead of GOTO.
Anyway, it?s a matter of opinion
You can't have a LOOP inside a If block inside that same loop:
Not valid:
Do
If
Loop
End IF
I agree 100% with vohaul, GOTOs should be avoided as much as possible because it does make the "spagetti" effect.
Me? I NEVER use them. I always use loops and SUBs. Once you set out avoiding GOTOs in your brain you automatically think in terms of not jumping around in a structure. I don't even consider GOTOs in a program anymore.
No point arguing if GOTO is good or not. It is all opinion. Professionals use a form of Branching or GOTO statements as well, so it's not exactly like there's a "Good" way of doing things when it comes to this. Just a preferred way.
Besides, in this case If really shouldn't be considered. Case is far more efficient when it comes to menu or command options.
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer
the original question was how to add an If statement to the program. We all sort of got off track after what, the third or fourth post I think. When subs instead of GOTO came into what was posted. And so we're here. But the code has been offered, they can take which ever they want. They all work.
So, this is done.
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer