For sake of efficiency, many languages will do what is called "Short
Circuit" in a situation like this.  Let's look at a simple truth table for
an OR using two conditions (T=true, F=false):

T || T = T
T || F = T
F || T = T
F || F = F

In the first two cases, it is only necessary to evaluate the first condition
because since they are true, the entire statement will be true.  In case
number 3, since the first condition was false, the second condition needs to
be evaluated to determine whether or not the entire statement is true.  In
case 4, both statements are evaluated (for the same reason as case 3).

If you need BOTH statements to be evaluated, chances are that you want an
AND condition, not an OR condition.  A simple truth table for an AND using
two conditions:

T && T = T
T && F = F
F && T = F
F && F = F

In the case of the AND, it is always necessary to evaluate both conditions
as both conditions need to be true in order for the entire statement to be
true.  If any condition in a set of AND conditions is false, the value of
the entire expression is also false.

HTH

Sam Masiello
Software Quality Assurance Engineer
Synacor
(716) 853-1362 X289
[EMAIL PROTECTED]



----- Original Message -----
From: "jv" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 28, 2002 3:04 PM
Subject: [PHP] Help with Logical 'OR'


> It seems that only the first condition is being evaluated.
>
> I know that if  both of the following conditions are false then the second
> set of statements should get read, and that's what happens, but when I set
> $name to true and $text to false (true||false) then the first set gets
read.
>
> Shouldn't both conditions be true in order for the first set of statements
> be read? Why would the first set of statements get read when the
conditions
> are (true||false)?
>
> Thanks in advance for your help.
> james
>
> ********************************************************************
> if ($name || $text)
>
>     {
>
>   $text = stripslashes("$text");
>   print "Hello $name\n<br>";
>   print "You said:\n<br> $text\n";
>
>         }else{
>
>   print "Sorry, but you seem to have left one or more entries
blank.<br>\n";
>   print "Please return to <a href=\"/prac/form.html\">form</a>\n";
>   print " and complete the input<br>\n";
>
> }
> **********************************************************************
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to