Re: error with Delphi's logical "and" operator

[ DelphiLand FAQ ]

Posted by webmaster Guido on November 26, 2004 at 21:37:07:

In Reply to: logical operator question--"and" posted by murphy on November 25, 2004 at 09:13:40:

: my code is:
: if (copy(,18,3) <>'CGL') and (copy(,1,3)<> '233') then continue;
: but it doesn't work! :(
: if I change the code to two If statements, it works. why?
: Is there any problem with the "and" operator?
: the two if statements:
: if copy(,18,3) <> 'CGL' then continue;
: if copy(,1,3) <> '233' then continue;

There is nothing wrong with Delphi's "and" operator ;-)

1. Your first example is a logical "and" of two conditions:

   if Condition1 and Condition2 then ...;

2. But your second example with two If... statements, is a logical "or" of two conditions:

   if Condition1 then ...;
   if Condition2 then ...;

...which is equivalent to:

   if Condition1 or Condition2 then ...;


Related Articles and Replies

[ Delphi Forum -- by DelphiLand ]