in reply to Re: backwards if and while looping
in thread backwards if and while looping
There's another case to account for... if $a or $b isn't integer, and their fractional parts differ (i.e. ($a - int $a) != ($b - int $b)) and $a < $b, then
$a = $b unless $error or $a >= $b;(or similar examples in the thread) has a different result than the OP's code.
I think it muddies the water to test $error every time through the loop, as some of these solutions do, when you only need to test it once. If $a or $b might be non-integer, here's one way to do it:
if ($a < $b and !$error) { $a = int $b + ($a - int $a); $a++ if $a < $b; }
I left out doing the floating point comparisons correctly...
Updated: Fixed a dumb error in the code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: backwards if and while looping
by !1 (Hermit) on Oct 02, 2004 at 00:28 UTC | |
by Zed_Lopez (Chaplain) on Oct 02, 2004 at 05:27 UTC |