Multiple choice technology mainframe

Condition 1 AND Condition 2 Condition 1 is be true 80% of times and Condition 2 is true 20% of times. If both conditions are processed with IF command, then conditions should be coded in which order?

  1. Condition 1 And Condition 2

  2. Condition 2 And Condition 1

  3. None of the above

  4. Does not depend on the order.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When optimizing compound conditions with AND, evaluate the condition that is false more often first. Condition 2 is true only 20% of the time (false 80%), while Condition 1 is true 80% of the time (false 20%). By checking Condition 2 first, you short-circuit the AND operation 80% of the time without evaluating Condition 1, improving performance. This is called short-circuit evaluation optimization.

AI explanation

With an AND condition, processing stops as soon as any condition evaluates to false, so putting the condition that's more likely to be false first minimizes unnecessary evaluation. Since Condition 2 is true only 20% of the time (false 80% of the time), checking it first means the AND short-circuits sooner on average, making "Condition 2 AND Condition 1" the more efficient order.