1. just to be sure
- Posted by mexzony Dec 01, 2010
- 1334 views
i need to clear this time statement once and for all.
t = time while time() < t+0.1 do end while
i know t is assigned a value here but the time() < t+0.1 is it timing an empty loop with a given condition or what.need some explaining.
2. Re: just to be sure
- Posted by mattlewis (admin) Dec 01, 2010
- 1316 views
i need to clear this time statement once and for all.
t = time while time() < t+0.1 do end while
i know t is assigned a value here but the time() < t+0.1 is it timing an empty loop with a given condition or what.need some explaining.
It's not timing the loop, but it's keeping the flow of code inside the loop until at least a tenth of a second after t = time() is executed.
Matt
3. Re: just to be sure
- Posted by irv Dec 01, 2010
- 1299 views
The while() loop is empty, therefore it's just a time delay.
4. Re: just to be sure
- Posted by DerekParnell (admin) Dec 02, 2010
- 1236 views
i need to clear this time statement once and for all.
t = time while time() < t+0.1 do end while
i know t is assigned a value here but the time() < t+0.1 is it timing an empty loop with a given condition or what.need some explaining.
This is a technique that some people use to have the program wait for some period of time. In this case it's waiting for a tenth of a second.
From Euphoria v4 onwards, this is not a good way to do this. A better way is ...
-- pause for a tenth of a second. sleep(0.1)
5. Re: just to be sure
- Posted by DanM Dec 02, 2010
- 1210 views
i need to clear this time statement once and for all.
t = time while time() < t+0.1 do end while
i know t is assigned a value here but the time() < t+0.1 is it timing an empty loop with a given condition or what.need some explaining.
my $.02:
t = time() while time() < t+0.1 do end while
in: t = time() , time() is a FUNCTION; it gets the time at the specific moment it's called, and returns it (the value of that moment in time), putting that value into the variable "t". This value is an ORIGINAL CONDITION, against which LATER values of time will be compared.
in: while time() < t+0.1 do end while
the first time in the while loop that the function time() is called, a (new) time value is returned, which will be *slightly* larger in value than the original value which was placed into the variable t; since that new value is likely only a little greater than the original value in t, it won't be greater than t+.1, so the while loop repeats again, this time getting a NEW value of time when the function time() executes, which is again tested against the ORIGINAL time, as held in the variable "t", to see if it's greater than (or equal to) that original time + 0.1.
So, the while loop executes over and over again, until the time returned by the function time() is NOT less than the original time + 0.1, at which time the while loop "falls through" to whatever code follows it.
And has been mentioned, this effects a time or wait loop, such that nothing else happens (executes) until it is finished.
Dan