I would say that there is no such thing as overdoing GOTOs, only misusing them, and even if you only have one GOTO misuse is bad, while there is nothing wrong with a lot of correctly used GOTO statements. See the classic "Structured Programming with go to Statements" by DONALD E. KNUTH at https colon //pic.plover.com/knuth-GOTO.pdf.
-- Shmuel (Seymour J.) Metz http://mason.gmu.edu/~smetz3 ________________________________________ From: IBM Mainframe Discussion List [[email protected]] on behalf of Bob Bridges [[email protected]] Sent: Tuesday, March 24, 2020 11:19 AM To: [email protected] Subject: GOTOs (was CLIST) There is such a thing as overdoing GOTOs, but I agree that a blanket never-do-it rule is counter-productive. I don't often use SIGNAL in REXX, because I find that its structured features are adequate. But in other languages I have argued for limited GOTO use. In COBOL, for example, it seems to me that there's a place for GOTO TOP-OF-PARAGRAPH (to simulate ITERATE in REXX), GOTO EXIT-PARAGRAPH (to simulate LEAVE) and GOTO END-OF-PROGRAM (for controlled abend conditions). These don't violate structured-programming principles, they implement them. In VBA I freely use Goto IterateSomething (putting the label just before the Next statement). I don't think PL/1 ever needs it, but I'm glad it's there just in case. Even in REXX there's one missing structured ingredient: some way to leave a ~simple~ block. A SELECT comes close, but it's not perfect. Say you're looping through a list of candidates and have to perform a number of candidates: do jr=1 to stem.0 v0=stem.jr if v0='' then iterate v1=function1(v0) if v1<5 then iterate v2=functionv2(v1 + othervalue) if v2=previous then iterate say 'TRK:' v0 v1 v2 end That's great in a controled DO loop. But it's harder in simple block of code. A SELECT won't do the job, because of the calculations you have to do between the various tests. I handle it this way: do 1 if v0='' then leave v1=function1(v0) if v1<5 then leave v2=functionv2(v1+othervalue) if v2=previous then leave say 'TRK:' v0 v1 v2 end I always suspect I'd get complaints from structured enthusiasts if they ever saw me cheating like that. In VBA I can't "Do 1", but I can do this: Do 'one time If v0 = '' Then Exit Do v1 = function1(v0) If v1 < 5 Then Exit Do v2 = functionv2(v1 + othervalue) If v2 = previous Then Exit Do MsgBox "TRK: " & v0 & " " & v1 & " " & v2 Loop Until True --- Bob Bridges, [email protected], cell 336 382-7313 /* Being famous has its benefits, but fame isn't one of them. -Larry Wall */ -----Original Message----- From: David Crayford Sent: Tuesday, March 24, 2020 09:03 If you eschew goto how do you deal with error handling and cleanup using a language which doesn't support exceptions, finalization or RAII? I find these kind of blanket rules to lead to bad code with deep nesting and useless status variables. --- On 2020-03-21 11:45 PM, Paul Gilmartin wrote: > o Symbols EXPOSEd from external scopes can't be used as targets > of ITERATE and LEAVE. (I eschew GOTO; SIGNAL is worse,) ---------------------------------------------------------------------- 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
