![]() |
| |||||||||||||||||||||
Navigation |
Synopsis Boolean and operator.
Syntax
Exp1 && Exp2
Types
Description The and operator on Boolean values defined as follows:
&& operator, the result is false if Exp1 evaluates to false , otherwise Exp2 is evaluated to determine the result.
Note that && backtracks over its argument expressions until it can find an evaluation that yields true unless there is none. This may happen if the left or right expression is a non-deterministic pattern match or a value generator.
Variable assignments as a result of matching or generator expressions under a && are visible outside the context of the operator, but only if the context is conditional, such as an if-then-else or a for loop. Note that if one of the argument expressions evaluates to false, then no binding is done either.
Examples
rascal>true && false; bool: false rascal>i <- [1,2,3] && (i % 2 == 0) bool: true rascal>import IO; ok rascal>if (i <- [1,2,3] && (i % 2 == 0)) >>>>>>> println("<i> % 2 == 0"); 2 % 2 == 0 ok rascal>for (i <- [1,2,3,4] && (i % 2 == 0)) >>>>>>> println("<i> % 2 == 0"); 2 % 2 == 0 4 % 2 == 0 list[void]: []
Benefits
Pitfalls
![]() |