Boolean Expressions and variables A B A&&B A B JA false false false false true false true false true true true false false true false true true true true false C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-11
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 11 Boolean Expressions and Variables A B A && B A || B !A false false false false true false true false true true true false false true false true true true true false
Short-Circuit evaluation r Consider the following boolean expression: X> y x>Z r The expression is evaluated left to right. If X, >y is true en there's no need to evaluate x>z because the whole expression will be true whether x>z is true or not r To stop the eyaluation once the result of the whole expression is known is called short-circuit evaluation r What would happen if the short-circuit evaluation is not done for llowing expression z==0||x/z>20 C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-12
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 12 Short-Circuit Evaluation Consider the following boolean expression: x > y || x > z The expression is evaluated left to right. If x > y is true, then there’s no need to evaluate x > z because the whole expression will be true whether x > z is true or not. To stop the evaluation once the result of the whole expression is known is called short-circuit evaluation. What would happen if the short-circuit evaluation is not done for the following expression? z == 0 || x / z > 20