Some languages, e.g., Ada, Java, Perl, have short-circuit and and or operators, where a subsequent operand is not evaluated if its value does not effect the result.
I'll use tricks like your nested IF statements if I really need to save CPU cycles, but normally I try to optimize legibility even at the expense of performance. -- Shmuel (Seymour J.) Metz http://mason.gmu.edu/~smetz3 ________________________________________ From: IBM Mainframe Discussion List [[email protected]] on behalf of Bob Bridges [[email protected]] Sent: Friday, June 18, 2021 1:44 PM To: [email protected] Subject: Re: EXTERNAL: Coding for the future Right, I almost never use ELSE IF. Partly, I suppose, that's a reaction against the folks who carefully indented: IF X>0 BLAH BLAH BLAH ELSE IF X>10 BLAH BLAH BLAH ELSE IF X>100 BLAH BLAH BLAH ELSE IF X>100 BLAH BLAH BLAH ELSE AND SO ON. As we agreed, sure, I intend fanatically. But if indentation is going to go in and in like that, I'll try ~very~ hard to find anther way of putting it. SELECT is great. Here's another one, though I think I have to consider it a foible, not a great idea: I rarely use AND. Mostly if I need and, I use IF...THEN IF...THEN. The reason is that sometimes I have to do those inside loops, and if they're going to be executed millions of times it costs more cycles to do this: if x>10 and y<10 then ... ...than this: if x>10 then if y<10 then ... But I confess I usually do it even outside loops. And of course sometimes the AND cannot work because sometimes the second condition cannot be evaluated unless the first is true: If Exists(Key, Collection, Result) Then If Result = "" Then ... But that's a special case. --- Bob Bridges, [email protected], cell 336 382-7313 /* The proverbial German phenomenon of the "verb-at-the-end", about which droll tales of absentminded professors who would begin a sentence, ramble on for an entire lecture, and then finish up by rattling off a string of verbs by which their audience, for whom the stack had long since lost its coherence, would be totally nonplussed, are told, is an excellent example of linguistic pushing and popping. The confusion among the audience that out-of-order popping from the stack, onto which the professor's verbs had been pushed, is amusing to imagine, could engender. -from _Gödel, Escher, Bach: An Eternal Golden Braid_ by Douglas R Hofstadter */ -----Original Message----- From: IBM Mainframe Discussion List <[email protected]> On Behalf Of Seymour J Metz Sent: Friday, June 18, 2021 13:04 In PL/I and REXX I eschew ELSE IF in favor of using SELECT statements. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
