Re: Basic switch statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
> Nathan Rixham wrote:
>> Robert Cummings wrote:
>>> Nathan Rixham wrote:
>>>> Robert Cummings wrote:
>>>>> Nathan Rixham wrote:
>>>>>> Robert Cummings wrote:
>>>>>>> steve_r wrote:
>>>>>>>> I'm new to programming
>>>>>>>>
>>>>>>>> function check_it2($val) {
>>>>>>>>     echo gettype($val);
>>>>>>>>     switch($val) {
>>>>>>>>         case($val > 0 ):
>>>>>>>>             echo "Switch greater than 0";
>>>>>>>>
>>>>>>> You're a tad confused :)
>>>>>>>
>>>>>>> Q: What is the result of $val > 0?
>>>>>>> A: false.
>>>>>>>
>>>>>>> Q: What is the value of $val?
>>>>>>> A: -1
>>>>>>>
>>>>>>> Q: Is -1 equivalent to false?
>>>>>>> A: Yes!
>>>>>>>
>>>>>>> Use an if statement for this kind of logic.
>>>>>> This is a fantastic example of false logic and an easy pitfall.
>>>>>>
>>>>>> in fact this would make a great interview question!
>>>>>>
>>>>>> to expand a little on the various scenarios (just for clarity, Rob is
>>>>>> wrong)
>>>>>>
>>>>>> $val = 1;
>>>>>> 1 > 0 equates to TRUE
>>>>>> is 1 equivalent to TRUE : YES
>>>>>>
>>>>>> $val = 0;
>>>>>> 0 > 0 equates to FALSE
>>>>>> is 0 equivalent to FALSE : YES
>>>>>>
>>>>>> $val = -1;
>>>>>> -1 > 0 equates to FALSE
>>>>>> is -1 equivalent to FALSE: NO
>>>>>>
>>>>> Fail on that last one. -1 is equivalent to FALSE :B
>>>>>
>>>> well that's one job you're not getting :p
>>> Well I DID get 66.7%. I've met "coders" that would stare at the answer
>>> and still not understand :D
>>
>> the travesty is that you didn't spend most of yesterday on trains brushing
>> up on / studying formal logic!
> 
> Muphry's Law!!!
> 
> http://en.wikipedia.org/wiki/Muphry's_law
> 
> *heheh*

in situations like this one might consider changing the conversation
previous!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux