One of the ways I avoid too many nested IF statements is to use straddling DO/ENDDO around code that may require several "let's get outta here now" moments. For example :
DO , Some code DOEXIT (TM,flag,bit,NO) ... Some more code DOEXIT (CLC,field,NE,value) ... Call some subroutine DOEXIT (LTR,R15,R15,NZ) ...etc ENDDO You could also label the "DO" (eg "MAIN") and then use something like "ASMLEAVE MAIN" from anywhere later in the logic. Rob Scott Lead Developer Rocket Software 275 Grove Street * Newton, MA 02466-2272 * USA Tel: +1.617.614.2305 Email: rsc...@rs.com Web: www.rocketsoftware.com -----Original Message----- From: IBM Mainframe Assembler List [mailto:ASSEMBLER-LIST@LISTSERV.UGA.EDU] On Behalf Of Johanson, Adam Sent: 03 February 2011 18:42 To: ASSEMBLER-LIST@LISTSERV.UGA.EDU Subject: Re: Best (or any) practices to rewrite "spaghetti" John Ehrman wrote: > There's no reason your SP macro code can't include a jump to an error handler > when an error occurs. > Donald Knuth once wrote a scholarly article called "Structured Programming > with GOTO Statements" where he showed that > attempts to be "purely structured" were often more obscure than using a GOTO > when it was simplest. Yeah, what they said. I recently changed a couple of multi-thousand-line programs to use SPMs and my first thought was that I was going to eliminate all of the branches in them. But as I got going, it became pretty apparent that to do so would require things that made the code a little bit less readable, like lengthening IF-blocks and adding a couple of more indentation spacings to blocks that already had a fair amount of indentation to them. Then, I told myself that the whole point of the exercise was to make the code more readable, so a branch to a return-to-caller label every now and then didn't really defeat the purpose and actually _did_ help things. IMHO, rather than seeing a big nested IF statement and chasing down the end point just to figure out that you're gonna return to the caller is a bit more involved than realizing, "Oh, I'm just getting out of Dodge." And you've probably come across it in the SHARE presentations that you've seen, but if you're going to do this, download Ed Jaffe's FLOWASM exit. It makes life easier. Adam Johanson IMS Systems Programming USAA