1 Consider the statement In some programming languages the

  1. Consider the statement:         <condition a> || <condition b> In some programming languages, the semantics of the || operator are such that if <condition a> is TRUE, then <condition b> will not be evaluated. What is the technical term for this?  2. Based on question-1, without looking at any technical manuals or online resources, how can you test by executing the programs to know if all the conditions are evaluated or the conditions are partially evaluated? Provide one to five lines of pseudocode for this testing and explain how the testing program works.  3. Based on question-1, give one real life example (including one activity, namely <condition a>, and the other, namely <condition b>) to show that the final judgment of its truth value is not affected by <condition b> if <condition a> is TRUE (i.e. <condition b> does not need to be evaluated). 

Solution

1. Short circuit evaluation or minimal evaluation is the concept arises when handling multiple boolean operators. The second condition is evaluated on if the first condition is sufficient to decide on the result.

In OR operation, the overall result evaluates to true, if atleast one of the condition evaluates to true. So, if the first condition <condition a> itself evaluates to true, we can conclude that, the overall result is true, without even evaluation the secon one.

2. The decision on whether the condition has been short circuited or not, is dependent on the compiler. If the compiler goes with lazy evaluation, only the second condition is evaluated if required.

3. Consider a scenario: If you have a ticket or pass, you can get into the train.

In this example, the first condition is, you have a ticket, and if you have it, you need not be checked for pass. Only if you don\'t have a ticket, then you\'ll be checked for pass.

 1. Consider the statement: <condition a> || <condition b> In some programming languages, the semantics of the || operator are such that if <cond

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site