From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: nospam@thanks.com.au (Don Harrison) Subject: Re: Why C++ is successful Date: 1998/08/19 Message-ID: #1/1 X-Deja-AN: 382533145 Sender: news@syd.csa.com.au X-Nntp-Posting-Host: dev7 References: <6r0m27$r3j@drn.newsguy.com> Organization: CSC Australia, Sydney Reply-To: nospam@thanks.com.au Newsgroups: comp.lang.ada Date: 1998-08-19T00:00:00+00:00 List-Id: Nasser wrote (on uses of gotos): :what about a common exit for a function? : :as we all know (offcourse :) that a function should have one :common exit. .. Yes. :) :sometime it is easier to go to a common_exit label at the bottom :of the function, where some common cleanup can be done if needed, :rather than use a nested if then else to try to carry the logic :through all the way down. : :example: : : if status /= good then : goto common_exit; : end if; : : status = do_soemthing; : : if status /= good then : goto common_exit; : end if; : : status = do_another_thing : : etc.. : :<> : return status; -- or log error message if status not good..etc.. : : :without a goto, one has to do: : :example: : : if status = good then : status = do_somtehing; : if status = good then : status = do_another_thing : else : etc.. -- error : end if; : else : .. -- error : end if; Do you? The following should give you what you need without resorting to gotos or ugly indentation: for Try in 1 .. No_of_Tries loop case Try is when 1 => Status := Function_1; when 2 => Status := Function_2; ... when No_of_Tries => Status := Function_No_of_Tries; end case; if Status = Good then exit; end if; end loop; if Status = Good then return Status; else Log_Error (..); raise Postcondition_Error; -- failed to get a result end if; Don. Don Harrison donh at syd.csa.com.au