Comparison and Logical Operators
Comparison operators are used to compare two values and return a Bool type result. Cangjie supports six comparison operators: equal (==), not equal (!=), less than (<), less than or equal (<=), greater than (>), and greater than or equal (>=). The two operands being compared must be of the same type.
Logical operators are used to combine boolean values: && (logical AND) returns true when both operands are true; || (logical OR) returns true when either operand is true; ! (logical NOT) negates a boolean value. Logical operators support short-circuit evaluation: for a && b, if a is false, then b will not be evaluated; for a || b, if a is true, then b will not be evaluated.
These operators are commonly used in conditional statements to combine multiple conditions into complex logical expressions.
The code on the right demonstrates the basic usage of comparison operators and logical operators, and how to combine them for complex conditional judgments. Try changing && to || and observe the result changes.
Run to see the output, and try modifying conditional expressions to understand operator behavior.