Boolean Type
The boolean type is represented by Bool, used for logical judgments, and has only two values: true and false. The boolean type supports three logical operators: logical NOT !, logical AND &&, and logical OR ||.
Logical AND && and logical OR || employ short-circuit evaluation: when evaluating a && b, if a is false, then b is not evaluated; when evaluating a || b, if a is true, then b is not evaluated. This avoids unnecessary computations and can even prevent runtime errors.
Comparison operators (such as ==, !=, <, >) also produce Bool type results. The code on the right demonstrates basic usage of boolean values, logical operations, and comparison operations.
Note
The boolean type cannot be converted to integer types. Unlike some languages (such as C/C++), in Cangjie
true cannot be used as 1.Try writing a new comparison expression or logical expression and print the result.