compound if alternatives
Huisingh, Larry R
Larry_R_Huisingh at RL.gov
Mon Jan 26 08:16:43 EST 2004
You only need to compare against t1, t2, etc. one time each. See below
if c < t1 then
do1
else if c < t2 then # >=t1 is implied
do2
else if c < t3 then # >=t2 is implied
do3
...
else if c < t7 then
do7
else
# We already know that it is not < t7 because we are in the else clause
# Therefore c must be >= t7
do8
end if
This should do what you need.
Larry Huisingh
> I need to repeatedly check within which of predefined time periods
> the current moment is. Since this affects overall performance (but is
> necessary), I am trying to see whether there is an alternative to a
> compound if to speed this up.
>
> t1, t2, t3, ... , t7 -- time interval boundaries in seconds
> c - current time in seconds
>
> if c < t1 then
> do1
> else if c >= t1 and c < t2 then
> do2
> else if c >= t2 and c < t3 then
> do3
> ...
> else if c >= t7 then
> do8
> end if
>
More information about the metacard
mailing list