Re: Help with Logical 'OR'

From: Date: Mon, 28 Jan 2002 20:03:41 +0000
Subject: Re: Help with Logical 'OR'
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-82461@lists.php.net to get a copy of this message
With a logical OR statement, many languages will evaluate the first statement, and if the first condition is true, then it will not evaluate the second condition, because TRUE OR (anything) is TRUE. This saves the program from executing any more code than it has to. If the first condition is FALSE, then the second condition will be checked. If you are wanting both $name and $text to be true in order for the first block of code to be executed, then you will want to use an AND (&&) statement. I hope that answers your question. Jeff At 02:04 PM 1/28/2002 -0600, jv wrote:
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"; } **********************************************************************


« previous php.general (#82461) next »