Use short-circuit evaluation to improve performance of your program.
Short-circuit evaluation (SCE), also called "minimal", denotes the semantics of Boolean operators in logical expressions in formats "A AND B" and "A OR B" in which the second argument is only executed or evaluated if the first argument does not suffice to determine the value of the expression. In other words, the evaluation of a Boolean expression terminates as soon as the result value, produced by the whole expression, is known, even if not all the components in the expression have been evaluated. Thus, try to build the expression so that the decision is made as soon as possible:
"A AND B" ("A && B"): when A evaluates to false, the whole expression will return false (B will not be evaluated), so make sure that A is more efficient (executed quicker) than B (and if they have a same performance, make sure that A is more likely to produce false than B).
"A OR B" ("A || B"): when A evaluates to true, the whole expression will return true (B will not be evaluated), so make sure that A is more efficient (executed quicker) than B (and if they have a same performance, make sure that A is more likely to produce true than B).
To clarify the idea, let's write a Boolean method which determines if the person is eligible to work in security (to pass the validation, the person must be older than the minimum age, defined by law, AND to have no criminal record). The age checking is simply a quick comparison of instance variables, but to check criminal record, the application needs to call a web service (which is much slower operation). Here is the method's code with the correct order of components (PB doesn't have short-circuit evaluation, so we have to imitate it by slightly more complicated code):
So, if the candidate is immature, the web service will not be called at all.
The short-circuit is not the only possible evaluation, there is also the regular one (also called "eager" or "long-circuit") - when the second part of the Boolean expression is evaluated anyway, even if its result cannot change the already known value, which will be produced by the whole expression. In most programming languages you can utilize both the evaluations using different logical operators, but some languages have only one. Look at this table to clear up a question what happens in your programming language. If it doesn't appear in the table then you can easily check if it supports SCE by assigning a Boolean variable the results of the expressions, having zero divide in the second part (translate them to your language if needed):