🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Peter Flass Sat, 17 Oct 2026 20:06
Short-circuiting IF statements
#20
Author: Peter Flass
Date: Sat, 17 Oct 2026 20:06
47 lines
2897 bytes
The PL/I standard specifies that all expressions in an IF-Statement are 
evaluated to determine truth or falsity. However the IBM Enterprise PL/I 
Language Reference says:

The test of the IF expression is short-circuited under the following 
circumstances:
• If the IF expression consists of a logical OR of 2 expressions and the 
first of these expressions is true,
the second expression will not be evaluated and the code will execute 
the THEN clause.
• If the IF expression consists of a logical AND of 2 expressions and 
the first of these expressions is false,
the second expression will not be evaluated and the code will execute 
the ELSE clause.

Iron Spring PL/I currently short-circuits. I have tested Windows PL/I 
and Multics PL/I and they don't. I am attaching a small program to test 
this. I'd appreciate it if someone could compile it with whatever PL/I 
compiler you have and let me know the results. If it short-circuits you 
should get two lines of output: "zero" and "one"; if it does not you 
should get four.

Normally this is not a problem, except for two cases:
1. Evaluation of the second part of the expression depends on the first 
being true or false, for example "if p¬null & p->"...
2. One or more of the expressions has side-effects, as in the following 
example.

  ---------- the program ----------
/* Test shortcut IF-Statements */
if : Procedure options ( main ) ;
zero: proc returns( bit(1) );
  put skip list('zero');
  return(0);
  end zero;
one: proc returns( bit(1) );
  put skip list('one');
  return(1);
  end one;

  if 0 & zero() then /*nothing*/ ;
  if 1 & zero() then /*nothing*/ ;
  if 0 | one()  then /*nothing*/ ;
  if 1 | one()  then /*nothing*/ ;

End if ;
Re: Short-circuiting IF statements
#24
Author: David Meyer
Date: Wed, 21 Oct 2026 22:32
6 lines
1237 bytes
Kednos PL/I Version 3.8 for OpenVMS VAX does NOT short-circuit.

-- 
David Meyer
Takarazuka, Japan
papa@sdf.org
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads