Comparison and Logical Operators
Relational operators include equality (==), inequality (!=), less than (<), less than or equal (<=), greater than (>), and greater than or equal (>=). These operators require both operands to have the same type, and produce Bool type results with values true or false.
Logical operators include logical NOT (!), logical AND (&&), and logical OR (||). Logical AND and OR use short-circuit evaluation: when the first operand can already determine the entire expression's result, the second operand is not evaluated. For example, false && expr directly returns false without evaluating expr.
Regarding operator precedence, && has higher precedence than ||. When combining complex conditions, it's recommended to use parentheses to clarify logical relationships and avoid unexpected results due to precedence issues. Cangjie's strong typing ensures that erroneous code like if (a = 5) will result in a compile-time error.
The code on the right demonstrates the use of comparison and logical operators. You can modify conditional expressions to observe the effects of short-circuit evaluation and the impact of precedence when combining conditions.