On Thu, 3 Aug 2017 19:11:07 +0000, Robert Prins wrote: >Just came across the following, and please don't come back with pedantic >remarks about undeclared variables, the code is just to show what's there: > >dcl sum fixed (7) init (-0.1); > I don't know what language this is, and I'm probsbly not skilled in it. Regardless, "fixed" and "-0.1" seem contradictory; meriting a syntax error.
>for i = 1 to whatever; > if a(i) >= 0 then > sum = sum + a(i); > And there, at least I'd do: > if a(i) > 0 then > sum = sum + a(i); > as long as testing, why bother to add 0? >if substr(unspec(sum), 25, 8) ^= '0d'bx then > put data(sum); > What's this testing for; in what representation? Is a single non-numeric comparison cheaper than a numeric comparison? >In other words if all a(i) are negative, nothing is printed. A comment in >the code suggests that this is faster code, on modern OoO z/OS systems, >than the more logical: > >dcl sum fixed (7) init (-1); > >for i = 1 to whatever; > if a(i) >= 0 then > if sum ^= -1 then > sum = sum + a(i); > else > sum = a(i); >end; > Unless the preponderance of the items are non-positive, the test probably costs more than it saves. I like to structure my loops, so neither boundary, the first item nor tne last, requires special treatment. This violates that. And I studiously avoid the over-and-under read, such as: read X # Get first item. if not eof then do process X read X # Get next item. if eof then break done >end; > >It probably is if the value of whatever is in the order of 42 gazillion, >but any other thoughts about this? > None suitable for publication, although events of the past week have eroded that standard. -- gil ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN