Skip to content
← Back to glossary

条件式Conditional Expression

Learn in the textbookExpressions, Assignment, and Comments

DefinitionA conditional expression (条件式) is an expression that evaluates to either true (真) or false (偽), and it decides which way a branch goes and whether a loop continues.

ExplanationThe basic form compares two values with a comparison operator; for example, "a ≧ 18" is true when a is 18 or more. Several conditions are joined with logical operators: and is true only when all of them are true, and or is true when at least one is true. not swaps true and false.

AnalogyIt is like the height marker at the entrance to a theme park ride: you either meet the mark or you do not, and that decides whether you get on.

Memory hookWrite true as 1 and false as 0: and matches the product, and or matches whether the sum is 1 or more.

Related past-exam questions(11 questions)