if Statements
Cangjie's if statement is used to execute different code branches based on conditions. The condition expression must be of type Bool - when the condition is true, the if branch executes; when false, the else branch executes.
Unlike many languages, Cangjie requires conditions to be wrapped in parentheses (), and curly braces {} are also mandatory, even when a branch contains only one line of code. These design choices prevent common coding errors and improve code readability.
Cangjie does not allow integers or other types to be used as conditions. In C or JavaScript, if (number) would determine the branch based on whether number is 0, but in Cangjie this results in a compilation error - conditions must be explicit boolean expressions.
The code on the right demonstrates basic if-else structures and multi-level conditional judgment with if-else if-else. Try modifying the value of score to observe the execution results of different branches.
Bool. You cannot use integers as conditions like in C.