FutureBasic Logo

<<    Index    >> FutureBasic

&& - logical 'and'   operator

result = exprA && exprB

The logical && operator evaluates exprA's and exprB's content for non-zero values. If both expressions are non-zero the result is true, otherwise the result is false. Unlike FB's and operator, which performs a bitwise evaluation, && is a logical operator and probably the one most programmers would use.

In the following example, expressions are evaluated as true or false before a decision is made for branching. The logical expression time > 7 is true, and is therefore evaluated as true. The expression time < 9 is false, and is therefore evaluated as false. Then the logical comparison (true) && (false) is performed, resulting in false. Finally, the if statement interprets this zero result as meaning "false," and therefore skips the first print statement. In other words, both conditions have to be true for the first print statement to execute.

time = 9
if ( time > 7 && time < 9 )
   print "It is time for breakfast!"
   print "We have to wait 'til noon to eat!"
end if

Example Two
JoeIsHere = 16
FredIsHere = 2
if JoeIsHere then print "Joe's here" else print "Joe's gone"
if FredIsHere then print "Fred's here"¬
  else print "Fred's gone"
if JoeIsHere && FredIsHere
  print "They're both here"
  print "They're not both here!"
end if

program output:
Joe's here
Fred's here
They're both here!

N.B. Notably, a bitwise and fails in the above code. The bitwise and page explains the reason.

See also
and; nand; nor; not; xor; or; Appendix D - Numeric Expressions