| Author |
Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
I am making a number guessing game, in Liberty BASIC, and the only way i can think of having a menu and then the main game start without using GOTO is to do a multi loop loop,
example
Do
*user selects level*
if level one
Do
*level one code
Loop
if level Two
Do
*level 2*
Loop
and so on
My problem is excaping the main program loop in order to end the program, i think a way i could do this is below the IF statements to do a variable check, so if the inputed number = the random number, then exit the loop,
anyone got any better way?
I outsmarted you, something you will NEVER forgive me for |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
f16e7
Banned
Posts: 89
Location:
Joined: 21.09.09 Rank: Apprentice Warn Level: 100
|
|
|
May I ask, why BASIC? |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
i like BASIC, and this particular version is good for this stuff
I outsmarted you, something you will NEVER forgive me for |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Apophis
Member
Posts: 86
Location:
Joined: 02.10.09 Rank: Moderate |
|
|
do
//this code stuff
while(these_things_are_true && !endLoop)
if(endLoop)
{ break; }
Something along those lines may work out nicely. endLoop is a boolean variable, and if you need to end the main loop, you set endLoop to true (which will end the inner loop first) then it will end the main loop.
Edited by Apophis on 03-10-09 20:11 |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
Hit a slight snag now, anytime you input an incorrect answer, it goes back to the select difficulty menu, as far as i can tell all of my Do Loops and variable names are correct, not sure why this is happening
I outsmarted you, something you will NEVER forgive me for |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Apophis
Member
Posts: 86
Location:
Joined: 02.10.09 Rank: Moderate |
|
|
Post some code, otherwise all we'll be doing is guessing. |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
Here is the whole thing and i have to have those DO while, its the way LB works
guessOne = int(rnd(1)*10)
guessTwo = int(rnd(1)*50)
guessThree = int(rnd(1)*100)
[start]
Print "HI/LO"
Do while 1 = 1
Input "Select difficulty Level (1/2/3): "; levSel
if levSel = 1 then Do while 1 =1
Input "Enter Number (1/50): "; userOne
if userOne = guessOne then exit do
if userOne < guessOne then print "Too Low"
if userOne > guessOne then print "Too High"
loop
if userOne = guessOne then exit DO
if levSel = 2 then Do while 1 = 1
Input "Enter Number (1/100): "; userTwo
if userTwo = guessTwo then exit do
if userTwo < guessTwo then print "Too Low"
if userTwo > guessTwo then print "Too High"
loop
if userTwo = guessTwo then exit DO
if levSel = 3 then Do while 1 = 1
Input "Enter Number (1/10): "; userThree
if userThree = guessThree then exit do
if userThree < guessThree then print "Too Low"
if userThree > guessThree then print "Too High"
loop
if userThree = guessThree then exit DO
loop
print "Congratulations you won"
end
I outsmarted you, something you will NEVER forgive me for |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Apophis
Member
Posts: 86
Location:
Joined: 02.10.09 Rank: Moderate |
|
|
if userOne = guessOne then exit do
if userOne < guessOne then print "Too Low"
if userOne > guessOne then print "Too High"
Does it actually print out "Too Low" or "Too High"? I don't know anything about basic, but I get the feeling that your if statements are nested inside the first one. I dont see any form of endIf. |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
err, no it only prints too low, no matter what, let me change the order
I outsmarted you, something you will NEVER forgive me for |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
No it still prints too low, not sure what is going wrong here
EDIT* sorry it prints too low and also cuts back to the menu
and there must be one person on here that can do basic
I outsmarted you, something you will NEVER forgive me for
Edited by Orillian on 03-10-09 21:06 |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
root_op
Lord Abortion

Posts: 467
Location: Sweden, Lidkφping
Joined: 21.03.07 Rank: God |
|
|
Keyword wend quits current while loop.
Also, Liberty BASIC is very good on providing an entry point for learning haskel!
Seriously, do you even care?
Edited by root_op on 03-10-09 21:41 |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
Whats haskal? do you mean pascal?
I outsmarted you, something you will NEVER forgive me for
Edited by Orillian on 03-10-09 22:05 |
|
| Author |
RE: Escaping Do Loops Inside Do Loops |
Apophis
Member
Posts: 86
Location:
Joined: 02.10.09 Rank: Moderate |
|
|
I think he means Haskell. |
|