'case' vs. 'case is'

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

Is there a difference? I'm looking through some code where they have this:

case is = 2 or 3

If the select is 2, that case is not triggered.

If I add this to the statement:

case = 2, 3

then it's caught.

So, I assume 'is' different, I'm just not sure in which way and when one
would actually want to use it.

-Darrel
 
Hello darrel,
Off to google 'bitwise comparison'. Thanks for the lead! ;o)

should have said "bitwise operator" sorry

Basically you are combining the 2 values by oring them together
Consider their binary representations

00000011 = 3
00000010 = 2

To Or them together you say that the result will be 1 where either of the
values to be combined is 1

This results in a 1 in the right-most 2 positions which is equivalent to 3.

If you had used AND instead of OR then you would have had a 1 in a given
position if there was a 1 in the first AND the second values

resulting in a 1 in only the second from right position which would equate
to 2

Try to imagine brackets around the "2 OR 3" and evaluate this first.
 
Back
Top