IF 文が (最適化とは無関係に) 短絡評価されるのは、テスト式に少なくとも 2 つの式の論理和 (|) または論理積 (&) が含まれていて、各式の結果の型が bit(1) (TRUE または FALSE) である場合です。これは、左右の作用対象の式に再帰的に適用されます。
テスト式が論理和で、左側の式が TRUE の場合、右側の式は評価されません。逆に、テスト式が論理積で、左側の式が FALSE の場合、右側の式は評価されません。
dcl i fixed bin (31) static init(1); dcl j fixed bin (31) static init(2); dcl b3 bit(3) static init ('010'); dcl p pointer static init (null()); dcl fb31 fixed bin (31) based;
if (i = 1) | (j > 2) then /* (j>2) is not evaluated */ … ;
if (i ^= 3) & (j > 2) then /* (j>2) is not evaluated */ … ;
if ((i = 1) | (j > 2)) & ((i ^= 0)|( j =2)) then /* (j>2) and (j=2) is not evaluated */ … ;
if substr(s3,2,1) | substr(b3,1,1) then /* substr(b3,1,1) is not evaluated */ … ;
if (p ^= null() & p->fb31 = 0) then /* p->fb31 = 0 is not evaluated */ …;
if ^(i = 1) | (j > 2)) then /* -opt required for short-circuiting, test expression is NOT */ … ;