Tuy nhiên, kịch bản này sẽ không làm việc. Các báo cáo nếu luôn luôn thiết lập các tỷ lệ hoa hồng 0% vì biểu thức boolean trong lần đầu tiên tuyên bố nếu luôn luôn kiểm tra sự thật (giả định salesTotal là không phải số không hay tiêu cực - và nếu nó là, không ai khác nếu báo cáo vấn đề). Kết quả là, không có trường hợp nào khác nếu báo cáo có bao giờ đánh giá. | 152 Using If Statements else if salesTotal commissionRate else if salesTotal commissionRate However this scenario won t work. These if statements always set the commission rate to 0 because the boolean expression in the first if statement always tests true assuming the salesTotal isn t zero or negative and if it is none of the other if statements matter . As a result none of the other if statements are ever evaluated. Figure 4-3 The flowchart for a sequence of else-if statements. Mr. Spock s Favorite Operators The Logical Ones of Course 153 Mr. Spock s Favorite Operators The Logical Ones of Course A logical operator sometimes called a boolean operator is an operator that returns a boolean result that s based on the boolean result of one or two other expressions. Expressions that use logical operators are sometimes called compound expressions because the effect of the logical operators is to let you combine two or more condition tests into a single expression. Table 4-2 lists the logical operators. Table 4-2 Logical Operators Operator Name type Description Not Unary Returns true if the operand to the right evaluates to false. Returns false If the operand to the right is true. And Binary Returns true if both of the operands evaluate to true. Both operands are evaluated before the And operator is applied. I Or Binary Returns true if at least one of the operands evaluates to true. Both operands are evaluated before the Or operator is applied. A Xor Binary Returns true if one and only one of the operands evaluates to true. If both operands evaluate to true or if both operands evaluate to false returns false. Conditional And Binary Same as but if the operand on the left returns false returns false without evaluating the operand on the right. II Conditional Or Binary Same as I but if the operand on the left returns true returns true without evaluating the operand on the right. Book II Making Choices 4 The following sections describe these .