Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
7.5 Compound Conditions
More complex expressions can be constructed with the logical operators and, or, and not. These logical operators help to join two or more simple conditions to construct conditions that are more complex.
The general structure of a compound condition using the or operator and two simple conditions, cond1 and cond2, is:
cond1 or cond2
The other two logical operators are used in the same manner. For example,
if a ! = b and x > 0 then 〈 statements_1 〉 else 〈 statements_2 〉 endif
This same compound condition can be constructed in a more verbose manner. For example:
if a not equal b and x greater than 0
The following expression uses the not operator:
not (x <= y)
This expression has the following descriptive meaning: it is not true that x is less than or equal to y.
Категории