Lecture 13 Notes

advertisement
NOTE TO STUDENTS:
These notes are for the instructor's use. If you happen to find them to be
useful, that's great. If not, then please ignore these. Thanks!
—The Instructor
Lecture 13
BIT115 – Lectures Notes – Logical Operators
Returning things other than True/False; Side Effects
Integer tests: we can also get numbers back from these queries:
int getAvenue();
int getStreet();
int getDirection(); // one of Directions.NORTH,
Directions.SOUTH, etc
int getSpeed();
Note that these are all public methods
However, they aren't going to be all that useful unless we can compare them to other things
And do some simple math on them.
Logical Operators
AND
A && B are true only if both A, B are true
OR
A || B are true if A is true, B is true, or they're both
true
NOT
!A is the opposite of A. If A is true, !A is false. If
A is false, !A is true.
&&
||
!
Point out why we need these.
Example: a number (X) is in the range (5, 10)
You might try to write
5 < x < 10
However, this will be evaluated L to R, which won't work. You need
5 < X && X < 10
Download