Exiting Loop After a Delay Help!
Author |
Message |
heroes100
|
Posted: Thu Nov 05, 2009 6:54 pm Post subject: Exiting Loop After a Delay Help! |
|
|
What is it you are trying to achieve?
I am trying to get a loop to stop after a delay of w.e time.
What is the problem you are having?
I have a loop which generates random symbols and i would like it to stop generating these symbols after a designated time limit.
Describe what you have tried to solve this problem
I have tried to create a variable and make it add to the variable every loop and once it ='s a number it stopes but this will not work for i get a syntax error. :/
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
loop
let := Rand.Int (1, 122)
put chr (let ), ""..
end loop
end loading
|
Please specify what version of Turing you are using
4.11 (or i can also load it with 4.0.5) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
Posted: Thu Nov 05, 2009 6:58 pm Post subject: RE:Exiting Loop After a Delay Help! |
|
|
You have no exit condition
I think you might want to use a for loop |
|
|
|
|
|
heroes100
|
Posted: Thu Nov 05, 2009 7:34 pm Post subject: RE:Exiting Loop After a Delay Help! |
|
|
How can i make "let" a random int between 1-122 in a for loop?
Also when it is a for loop how can i exit it with a delay?? :/ |
|
|
|
|
|
Kharybdis
|
Posted: Thu Nov 05, 2009 8:01 pm Post subject: Re: Exiting Loop After a Delay Help! |
|
|
Turing: | var let : int
var count := 1
loop
randint (let, 1, 5) % (integer value, lowest, highest)
count + = 1
put let
exit when let = 2 % exit condition if let = 2
end loop
put "let appeared, ", count, " times." |
|
|
|
|
|
|
heroes100
|
Posted: Thu Nov 05, 2009 8:25 pm Post subject: RE:Exiting Loop After a Delay Help! |
|
|
Thanks for the responses. I have found a way around this. Even though the main question of how you can make a loop stop after a delay hasn't been answered but i have solved the problem. So all is well thx. |
|
|
|
|
|
Superskull85
|
Posted: Thu Nov 05, 2009 10:52 pm Post subject: Re: Exiting Loop After a Delay Help! |
|
|
What do you mean by "stop after a delay?" Do you mean something like this:
Turing: | loop
let := Rand.Int (1, 122)
put chr (let ), ""..
delay (100)
exit
end loop |
Or do you mean like what Kharybdis posted:
Turing: | var let : int
var count := 1
loop
randint (let, 1, 5) % (integer value, lowest, highest)
count + = 1
put let
exit when let = 2 % exit condition if let = 2
end loop
put "let appeared, ", count, " times." |
Or do you means something like this:
Turing: | var let : int
var count : int := 0
loop
let := Rand.Int (1, 122)
count + = 1
put chr (let ), "" ..
exit when count = 10
end loop |
I am a little confused about what you mean.
Anyways, if you wanted to use a for loop with a random upper bound than you could do something like:
Turing: | for i : 1 .. Rand.Int (1, 222)
put chr (i ) ..
end for |
What did you do to solve the problem? |
|
|
|
|
|
heroes100
|
Posted: Fri Nov 06, 2009 8:22 am Post subject: RE:Exiting Loop After a Delay Help! |
|
|
I meant more of the first but i do not know if that will still generate enough chars. as i need. I have ended up doing the 3rd thing you posted though but i was wanting it to generate random chars. and then stop after a set delay. But there is no need atm because i fixed it. |
|
|
|
|
|
B-Man 31
|
Posted: Fri Nov 06, 2009 11:33 am Post subject: Re: Exiting Loop After a Delay Help! |
|
|
if your trying to do it after a set amount of time, you could do something like this, more or less:
Turing: |
var timepassed : int
loop
timepassed := Time.Elapsed % starts a timer function
let := Rand.Int (1, 122)
put chr (let ), "" ..
if Time.Elapsed - timepassed >= 3000 then % the 3000 represents 3 seconds, change it to whatever you want
exit %so basicly, if more than 3 seconds passed, then exit the loop
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|