test of boundaries fail - why? bug?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
CodeLobster

test of boundaries fail - why? bug?

Post by CodeLobster »

the 3rd line has proper values but it doesnt react?

it should pop an echo if $test is minor than 0, larger than 1.

Code: Select all

 $test = "-2";
 if ($test >= 0 && $test <= 1) { echo "in the boundaries of 0 - 1 = $test"; }
 elseif ($test < 0 && $test > 1) { echo "out of range! value: $test"; } // should echo!!!
 elseif ($test > 1) { echo "OUT of range = > 1! value: $test"; } // this pops ok according to $test value
 elseif ($test < 0) { echo "out of RANGE = < 0! value: $test"; } // this one too

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: test of boundaries fail - why? bug?

Post by Stefan »

CodeLobster wrote:the 3rd line has proper values but it doesnt react?

it should pop an echo if $test is minor than 0, larger than 1.

Code: Select all

 $test = "-2";
 if ($test >= 0 && $test <= 1) { echo "A: in the boundaries of 0 - 1 = $test"; }
 elseif ($test < 0 && $test > 1) { echo "B: out of range! value: $test"; } // should echo!!!
 elseif ($test > 1) { echo "C: OUT of range = > 1! value: $test"; }
 elseif ($test < 0) { echo "D: out of RANGE = < 0! value: $test"; }

* what should this means: "<0" AND ">1"
Nothing is less then zero AND more then "1" the same time.

* "$test < 0" is the right answer for "-2"

* "-2" is minor than 0, but not larger than 1.

CodeLobster

Re: test of boundaries fail - why? bug?

Post by CodeLobster »

im trying to test left (negative or lower) and right (positive or larger) in the same line but it seems to be not possible, right?

in other words

($test < 3 && $test > 6) = should return yes for 2, 1, 0... or 7, 8, 9...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: test of boundaries fail - why? bug?

Post by Stefan »

CodeLobster wrote: ($test < 3 && $test > 6) = should return yes for 2, 1, 0... or 7, 8, 9...
Not sure if my mind is still working (saturday, 22:30)
but do you mean OR ?
($test < 3 || $test > 6)

IF var is less then 3 OR greater then 6, THEN echo yes, ELSE echo no

Code: Select all

$test = "-2";
   if ($test < 3 || $test > 6){ msg "$". "test is $test";}else{msg "ELSE";}


CodeLobster

Re: test of boundaries fail - why? bug?

Post by CodeLobster »

oh no, my own newbieness' fault as im learning by examples and documentation.

by examples, in case. :?

i can understand my statement as both inclusive or exclusive so your first post made sense to me either.

i just needed something to work as your second post did. thanks man!

Post Reply