When a loop might execute many times, it becomes increasingly important to consider the number of evaluations that take place. How can considering the order of evaluation of short-circuit operators affect the performance of a loop?
What will be an ideal response?
The expressions in each part of an AND or OR expression use short-circuit evaluation; that is, they are evaluated only as much as necessary to determine whether the entire expression is true or false. Suppose that a user can request any number of printed copies of a report from 1 to 15, and you want to validate the user's input before proceeding. If you believe that users are far more likely to enter a value that is too high than to enter a negative value, then you want to start a loop that reprompts the user with the following expression:
while(requestedNum > 15 || requestedNum < 1)?
Because you believe that the first Boolean expression is more likely to be true than the second one, you can eliminate testing the second one on more occasions. The order of the expressions is not very important in a single loop, but if this loop is nested within another loop, then the difference in the number of tests increases.
You might also like to view...
The part of a PowerView worksheet where the data visualization displays is the:
A) Bing screen. B) Data Model. C) PowerView Fields pane. D) PowerView canvas.
The variables (elements) in a two-dimensional array can be used just like any other variables.
Answer the following statement true (T) or false (F)