Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Escaping Do Loops Inside Do Loops


ghost's Avatar
0 0

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?


ghost's Avatar
0 0

May I ask, why BASIC?


ghost's Avatar
0 0

i like BASIC, and this particular version is good for this stuff


ghost's Avatar
0 0
//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.

ghost's Avatar
0 0

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


ghost's Avatar
0 0

Post some code, otherwise all we'll be doing is guessing.


ghost's Avatar
0 0

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


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

err, no it only prints too low, no matter what, let me change the order


ghost's Avatar
0 0

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


ghost's Avatar
0 0

Keyword markupwend quits current while loop.

Also, Liberty BASIC is very good on providing an entry point for learning haskel!


ghost's Avatar
0 0

Whats haskal? do you mean pascal?


ghost's Avatar
0 0

I think he means Haskell.