how to continue a program after a loop
Author |
Message |
kasi
|
Posted: Tue Nov 20, 2007 8:09 pm Post subject: how to continue a program after a loop |
|
|
i have figured out the button, but i just have one more problem after the loop the "Enter the number of the first die you have rolled:" doesn't get outputted, how would i program it so the "Enter the number of the first die you have rolled:" get outputted
code: |
import GUI
procedure di2
var die : array 1 .. 6 of procedure dice
die (1) := die1
die (2) := die2
die (3) := die3
die (4) := die4
die (5) := die5
die (6) := die6
die (Rand.Int (1, 6))
var d : array 1..6 of procedure dice
d(1):= d1
d(2):= d2
d(3):= d3
d(4):= d4
d(5):= d5
d(6):= d6
d (Rand.Int (1, 6))
end di2
procedure dice
locate(1,1)
end dice
var dice1:int
put"If you want to play dice click on the button below"
dice1:=GUI.CreateButton(25,25,0,"Click to roll the dice",di2)
loop
exit when GUI.ProcessEvent
end loop
var diee,dce,total,num1,num2:int
put"Enter the number of the first die you have rolled:"
get diee
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
rdrake
|
Posted: Tue Nov 20, 2007 9:24 pm Post subject: RE:how to continue a program after a loop |
|
|
...I think. |
|
|
|
|
|
Nick
|
Posted: Tue Nov 20, 2007 10:10 pm Post subject: RE:how to continue a program after a loop |
|
|
looK up return |
|
|
|
|
|
Tony
|
Posted: Wed Nov 21, 2007 12:36 am Post subject: RE:how to continue a program after a loop |
|
|
I think GUI.ProcessEvent return false unless GUI.Quit (or equivalent) is called. This is an arbitrary convention, to accommodate
structure.
rdrake's code is equivalent to the above, since exit when condition is the same as
code: |
if condition then
exit
end if
|
So you could break out of the loop by setting the exit flag with GUI.Quit in your di2 procedure. Though keep in mind that as soon as you exit that loop, your GUI will stop working since nothing is monitoring it. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Nick
|
Posted: Wed Nov 21, 2007 1:07 am Post subject: RE:how to continue a program after a loop |
|
|
another thing is
code: | var exit:boolean:=false
proc something()
exit:=true
end something
gui button call something()
loop
exit when gui
exit when exit
end loop |
so u got 2 exit commands |
|
|
|
|
|
Mazer
|
Posted: Wed Nov 21, 2007 7:03 am Post subject: RE:how to continue a program after a loop |
|
|
Why the fuck?
EDIT: Oh hey, I found a way to do it with 3 exit commands
code: | var exit:boolean:=false
var quit:boolean:=false
proc something()
exit:=true
end something
proc orother()
quit:=true
end orother
gui button call something()
gui button call orother()
loop
exit when gui
exit when exit
exit when quit
end loop |
Gotta keep your options open in the early stages, right? |
|
|
|
|
|
|
|