Posted: Fri May 16, 2008 8:20 pm Post subject: Quick Loop Question
is there a way to restart a Loop without using an reposting the whole loop inside the loop inside an if statement. In my program i have an if statement asking to play again and if they hit "y" then it suppossed to play again but i didn't want to post the whole loop inside it again. Is there another way?
Sponsor Sponsor
cavetroll
Posted: Fri May 16, 2008 8:33 pm Post subject: RE:Quick Loop Question
You could put the loop in a procedure and call the procedure if they respond with "y"
hossack
Posted: Fri May 16, 2008 8:48 pm Post subject: RE:Quick Loop Question
how do i do that?
gitoxa
Posted: Fri May 16, 2008 8:51 pm Post subject: RE:Quick Loop Question
or, you could just exit the loop when they enter n
hossack
Posted: Fri May 16, 2008 8:54 pm Post subject: RE:Quick Loop Question
it does do that i want it to restart when they enter y without posting the loop again inside an if statement
gitoxa
Posted: Fri May 16, 2008 9:05 pm Post subject: RE:Quick Loop Question
You only exit if they type in n. If they type in y, then it'll loop back up to the top again. You don't need any if statements.
code:
loop
%Does stuffs here
%More stuff, for lulz
put "Would you like ot play again?"
get Answer
exit when Answer = "n"
end loop
hossack
Posted: Fri May 16, 2008 9:10 pm Post subject: RE:Quick Loop Question
i did that and the program doesnt restart to the starting of the loop
cavetroll
Posted: Fri May 16, 2008 9:11 pm Post subject: RE:Quick Loop Question
Yup, you're right. I over thought that one way too much. Been learning about procedures in school so I'm used to using them to solve all problems.
Sponsor Sponsor
hossack
Posted: Fri May 16, 2008 9:17 pm Post subject: RE:Quick Loop Question
so im pretty much stuck doing it the really long way?
gitoxa
Posted: Fri May 16, 2008 9:18 pm Post subject: RE:Quick Loop Question
No, it means you've screwed up your code.
Mod edit: Let's keep away from the swear words.
hossack
Posted: Fri May 16, 2008 9:20 pm Post subject: RE:Quick Loop Question
damn it.. lol everything works just not the play again thing
gitoxa
Posted: Fri May 16, 2008 9:23 pm Post subject: RE:Quick Loop Question
Then re-do the exit part. Post what you have if you can't get it still.
hossack
Posted: Fri May 16, 2008 9:26 pm Post subject: RE:Quick Loop Question
post my whole program or just he exit part?
hossack
Posted: Fri May 16, 2008 9:30 pm Post subject: Re: Quick Loop Question
Turing:
xvar rock, paper, scissors, rules :int var x, y, buttonnumber, buttonup, WinID :int var answer :string var key :string(1) var userchoice, compchoice :int var win, lose, tie :int:=0
process domusic
Music.PlayFileLoop("daft punk - musique.mp3") end domusic
locatexy(1, 1)%Clicking to go to next page put"click to continue" buttonwait("down", x, y, buttonnumber, buttonup) if x > 0and x < 640and y > 0and y < 400then cls endif
rules :=Pic.FileNew("scissorDM_468x389.bmp")%Putting in Picture for Rules Pic.Draw(rules, 100, 5, picCopy)
locatexy(1, 1)%Clicking to go to next page put"click to continue" buttonwait("down", x, y, buttonnumber, buttonup) if x > 0and x < 640and y > 0and y < 400then cls endif
locatexy(280, 300) put"Pick Rock, Paper, or Scissors"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy)
loop buttonwait("down", x, y, buttonnumber, buttonup) if x > 10and x < 170and y > 10and y < 280then%If choose Rock
userchoice :=1 randint(compchoice, 1, 3)%Computer Choosing
if userchoice =1and compchoice =3then%If computer chooses scissors then win delay(10) cls put"You Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) locatexy(320, 280)%Saying You Won put"You Won"..
win := win + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
locatexy(1, 350) put"Play again? y or n" get answer
exitwhen answer ="n"
elsif userchoice =1and compchoice =2then%If computer chooses Paper then lose cls put"You chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Lost put"You Lost"..
lose := lose + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice = compchoice then%If computer chooses Rock then tie cls put"You chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif
elsif x > 180and x < 400and y > 10and y < 280then%If choose Paper
userchoice :=2 randint(compchoice, 1, 3)%Computer Choosing if userchoice =2and compchoice =1then%If computer chooses rock you win cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) delay(10) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) locatexy(320, 280)%Saying You Won put"You Won"..
win := win + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =2and compchoice =2then%If computer chooses paper tie cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 450, 10, picCopy) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =2and compchoice =3then%If computer chooses scissors lose cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) locatexy(320, 280)%Saying You lost put"You Lost"..
lose := lose + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif
elsif x > 420and x < 620and y > 16and y < 280then%If choose Scissors
userchoice :=3 randint(compchoice, 1, 3)%Computer Choosing if userchoice =3and compchoice =1then%If computer chooses rock Lose cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) locatexy(320, 280)%Saying You lost put"You Lost"..
lose := lose + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =3and compchoice =2then%If computer chooses paper Win cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Lost put"You Win"..
win := win + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice = compchoice then%If computer chooses Scissors then tie cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) delay(100) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif endif
endloop
if key ="y"then%play again loop buttonwait("down", x, y, buttonnumber, buttonup) if x > 10and x < 170and y > 10and y < 280then%If choose Rock
userchoice :=1 randint(compchoice, 1, 3)%Computer Choosing
if userchoice =1and compchoice =3then%If computer chooses scissors then win delay(10) cls put"You Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) locatexy(320, 280)%Saying You Won put"You Won"..
win := win + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
locatexy(1, 350) put"Play again? y or n" getch(key) elsif userchoice =1and compchoice =2then%If computer chooses Paper then lose cls put"You chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Lost put"You Lost"..
lose := lose + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice = compchoice then%If computer chooses Rock then tie cls put"You chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif
elsif x > 180and x < 400and y > 10and y < 280then%If choose Paper
userchoice :=2 randint(compchoice, 1, 3)%Computer Choosing if userchoice =2and compchoice =1then%If computer chooses rock you win cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) delay(10) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) locatexy(320, 280)%Saying You Won put"You Won"..
win := win + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =2and compchoice =2then%If computer chooses paper tie cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 450, 10, picCopy) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =2and compchoice =3then%If computer chooses scissors lose cls put"You Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 10, 10, picCopy) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) locatexy(320, 280)%Saying You lost put"You Lost"..
lose := lose + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif
elsif x > 420and x < 620and y > 16and y < 280then%If choose Scissors
userchoice :=3 randint(compchoice, 1, 3)%Computer Choosing if userchoice =3and compchoice =1then%If computer chooses rock Lose cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Rock"
rock :=Pic.FileNew("rock.bmp")%Inserting Rock Image Pic.Draw(rock, 380, 10, picCopy) locatexy(320, 280)%Saying You lost put"You Lost"..
lose := lose + 1 delay(10) locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice =3and compchoice =2then%If computer chooses paper Win cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Paper"
paper :=Pic.FileNew("paper.bmp")%Inserting Paper Image Pic.Draw(paper, 380, 10, picCopy) delay(100) locatexy(320, 280)%Saying You Lost put"You Win"..
win := win + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
elsif userchoice = compchoice then%If computer chooses Scissors then tie cls put"You Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 10, 10, picCopy) delay(10) locatexy(450, 400) put"Computer Chose Scissors"
scissors :=Pic.FileNew("scissors.bmp")%Inserting Scissors Image Pic.Draw(scissors, 380, 16, picCopy) delay(100) locatexy(320, 280)%Saying You Tied put"You Tied"..
tie := tie + 1 locatexy(300, 200)%Displaying stats put"Wins: ", win ..
locatexy(300, 180) put"Loses: ", lose ..
locatexy(300, 160) put"Ties: ", tie ..
endif endif
endloop
riveryu
Posted: Fri May 16, 2008 9:59 pm Post subject: Re: Quick Loop Question
It doesnt work when i ran your program...your program is rather long... Sry...
also, when you are posting, click the link/button that says "more tags" and click on "syntax" which will generate the [syntax =""] tag, add "turing" into the quotations and press syntax again to close the tag with [/syntax].
your code should be in btw the opening and closing of syntax tag ex. [syntax="turing""] ...code... [/syntax].
This is what it will looks like
Turing:
loop %Does stuffs here %More stuff, for lulz put"Would you like ot play again?" get Answer
exitwhen Answer ="n" endloop