how do you add a simple IF/THEN command?
how do you add a simple IF/THEN command?
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!
I am using a program called Just BASIC if that helps.
THANK YOU SO MUCH!
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
Just BASIC? Sorry...
Welcome to the forums! Register anad hang around.
Ugh... try www.freebasic.net
Its free, fast, open-source, and ever-thriving!
Welcome to the forums! Register anad hang around.
Ugh... try www.freebasic.net
Its free, fast, open-source, and ever-thriving!
Code: Select all
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
Code: Select all
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
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
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
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.
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
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.
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.
I am what you'd call a nice bastard.
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.
Code: Select all
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
Anyway, it?s a matter of opinion
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
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.
Its a good prorgamming habit.
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.
Its a good prorgamming habit.
"But...It was so beutifully done"
Code: Select all
End if
LOOP Until KeyWord$ = "Q" or KeyWord$ = "q"
**it happens
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.
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
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
Code: Select all
End if
LOOP Until KeyWord$ = "Q" or KeyWord$ = "q"
Code: Select all
End if
LOOP Until lcase$(KeyWord$) = "q"
Yes it would. But question was about using GOTO, not what is shortest way to do that exactly codeAnonymous wrote:Sorry don't mean to be a nit-pick but wouldn't it be easier to simply go.Code: Select all
End if LOOP Until KeyWord$ = "Q" or KeyWord$ = "q"
?Code: Select all
End if LOOP Until lcase$(KeyWord$) = "q"
Someones could now ask, is it ok to use "q" instead of CHR$(something) and next would ask something...
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.
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
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
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
What about UCASE$(KeyWord$) = "Q" ? lollurah wrote:Yes it would. But question was about using GOTO, not what is shortest way to do that exactly codeAnonymous wrote:Sorry don't mean to be a nit-pick but wouldn't it be easier to simply go.Code: Select all
End if LOOP Until KeyWord$ = "Q" or KeyWord$ = "q"
?Code: Select all
End if LOOP Until lcase$(KeyWord$) = "q"
Someones could now ask, is it ok to use "q" instead of CHR$(something) and next would ask something...
Ya, Levi, fine I prefer NOT to use GOTOs, (college professers, and Programming co-workers too )
"But...It was so beutifully done"