PDF 4
PDF 4
Decision Making
Terms
Boolean expression
Comparison operators
Conditional operator
If statement
Logical operators
Nesting if statements
Switch statement
Summary
• We use comparison operators to compare values.
• With Logical operators we can combine Boolean expressions and represent more complex
conditions.
• With the logical AND operator (&&) both operands should be true. If either of them is
false, the result will be false.
• With the logical OR operator (||), the result is true if either of the operands is true.
• Using if and switch statements, we can control the logic of our programs.
• An if statement can have zero or more else if clauses for evaluating additional
conditions.
• Using the conditional operator we can simplify many of the if/else statements.
• A switch block often has two or more case labels and optionally a default label.
• Case labels should be terminated with a break statement; otherwise, the control moves
to the following case label.
• Switch statements are not as exible as if statements but sometimes they can make our
code easier to read.