Follow us on Twitter!
Society leans ever heavily on computers, if you have the power to take out computers you can take out society. - cubeman372
Thursday, April 17, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 19
Guests Online: 19
Members Online: 0

Registered Members: 82815
Newest Member: medjiking
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:02
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
Code

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?


Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:06
May I ask, why BASIC?
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:08
i like BASIC, and this particular version is good for this stuff


Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:09
Code
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 on 03-10-09 20:11
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:33
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


Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:42
Post some code, otherwise all we'll be doing is guessing.
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:46
Here is the whole thing and i have to have those DO while, its the way LB works
Code


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







Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 20:59
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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 21:03
err, no it only prints too low, no matter what, let me change the order


Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 21:04
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




Edited by on 03-10-09 21:06
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 21:36
Keyword
Code
wend


quits current while loop.

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




Edited by on 03-10-09 21:41
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 22:04
Whats haskal? do you mean pascal?




Edited by on 03-10-09 22:05
Author

RE: Escaping Do Loops Inside Do Loops


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-09 22:18
I think he means Haskell.