Optimizing Conditional Statements

IF Statements

In IF statements, conditions within combined conditions are evaluated in the order in which they occur. Therefore, put the conditions that are most likely to produce a false result before others. Similarly, put those conditions that can be evaluated fastest before slower conditions.

Comparisons using EQUALS (=) or NOT EQUAL are faster than comparisons using GREATER (>) or LESS (<). In some systems, comparisons against binary zero are more efficient than against other literal values.

In both alphanumeric and numeric comparisons, make the source and target items the same size.

EVALUATE Statements

Avoid large EVALUATE statements. They are compiled into a series of IF ... ELSE IF ... statements where the value of the expression is derived separately for each WHEN clause.

Order an EVALUATE statement so that the most commonly satisfied condition is tried first. Do not use complex expressions or items defined in the Linkage Section as conditions in an EVALUATE statement; instead, include statements to calculate the value in an item defined in the Working-Storage Section and use that item in the EVALUATE statement.