Join us at IRC!
I'd prefer to die standing, than to live on my knees - Che Guevara
Wednesday, May 23, 2012
Navigation
Members Online
Total Online: 32
Web Spiders: 18
Guests Online: 30
Members Online: 2

Registered Members: 70179
Newest Member: prankst3r
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Escaping Do Loops Inside Do Loops

Orillian
Member



Posts: 68
Location: The Sprawl
Joined: 30.06.09
Rank:
Monster
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

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
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

f16e7
Banned

Posts: 89
Location:
Joined: 21.09.09
Rank:
Apprentice
Warn Level: 100
Posted on 03-10-09 20:06
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
Posted on 03-10-09 20:08
i like BASIC, and this particular version is good for this stuff


I outsmarted you, something you will NEVER forgive me for
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

Apophis
Member

Posts: 86
Location:
Joined: 02.10.09
Rank:
Moderate
Posted on 03-10-09 20:09
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
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


I outsmarted you, something you will NEVER forgive me for
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

Apophis
Member

Posts: 86
Location:
Joined: 02.10.09
Rank:
Moderate
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

Orillian
Member



Posts: 68
Location: The Sprawl
Joined: 30.06.09
Rank:
Monster
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


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
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

Apophis
Member

Posts: 86
Location:
Joined: 02.10.09
Rank:
Moderate
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

Orillian
Member



Posts: 68
Location: The Sprawl
Joined: 30.06.09
Rank:
Monster
Posted on 03-10-09 21:03
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
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

Orillian
Member



Posts: 68
Location: The Sprawl
Joined: 30.06.09
Rank:
Monster
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


I outsmarted you, something you will NEVER forgive me for

Edited by Orillian on 03-10-09 21:06
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

root_op
Lord Abortion



Posts: 467
Location: Sweden, Lidkφping
Joined: 21.03.07
Rank:
God
Posted on 03-10-09 21:36
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
root_op.asok@hotmail.com
Author

RE: Escaping Do Loops Inside Do Loops

Orillian
Member



Posts: 68
Location: The Sprawl
Joined: 30.06.09
Rank:
Monster
Posted on 03-10-09 22:04
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
casperorillian@hotmail.co.uk
Author

RE: Escaping Do Loops Inside Do Loops

Apophis
Member

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

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.