RE: GOTO statement and return results way

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

Thanks for your answer.

I kew that about nested ifs, but I don't like it because it adds complexity
to code.

I found the second method more elegant: do.. loop until true, I LIKE it.
But, risking to be too fussy, this "loop until true" trick seems just a bit
round-about 8-D

What do you think about the first question ? : to return if a procedure has
done well its work you 'd use a FUNCTION that returns the result code for
the operation, or a sub that, by means of a byref parameter returns the
result code ?

Wich is the paradigm for types of result codes: Strings, integers, custom
objects ?

Thanks again,


Roger Tranchez
MCTS
..NET 2005 and DB developer


"AMercer" wrote:

The second doubt is the GOTO: you know, it is a bad wound in code, but I
use it as a fast way to exit the sub.
How would you change all this to be more structured and aesthetic ?

When I have some functions to perform in sequence and I want to quit on the
first failure, I use one of two constructs - 'nested if' or 'do once'. I
prefer 'nested if' when I have few functions, I prefer 'do once' when I have
many.

Assuming the functions are x1, x2, and x3, 'nested if' is:

x1
If Success Then
x2
If Success Then
x3
If Success Then
' processing here for all success
End If
End If
End If

'Do Once':

Do
x1
If Fail Then Exit Do
x2
If Fail Then Exit Do
x3
If Fail Then Exit Do
' processing here for all success
Loop Until True

These constructs compile to code that is similar to yours with 'goto
endpoint', but the source code avoids goto's and label's. I prefer them over
goto's because I think they are easier to understand for a new person or for
you when you come back to the code after not looking at it for a few months.

.



Relevant Pages

  • Re: Exit Do
    ... I've been instructed by a dot net / asp programmer that Exit Do is not a ... great way to end a loop. ... I am using nested loops and need to exit out of one loop into another for ... if not success then exit do ...
    (microsoft.public.scripting.vbscript)
  • Re: Infinite Loops and Explicit Exits
    ... > CS> One of these proposals relaxes the current restriction that an EXIT ... > termination of the loop is not visible at that point. ... > terminating condition is visible in that context. ... > You now want to allow this remote procedure, ...
    (comp.lang.cobol)
  • SPARK : third example for Roesetta - reviewers welcome
    ... In order to avoid silly error which have bad consequence on SPARK reputation, as for the first two ones, I assume this may be better to submit it to interested reviewer. ... This was the opportunity to post an example with loop assertion, which is a main topic in SPARK. ... Success: out Boolean; ... I also though about an indirect way to prove the loop always terminates. ...
    (comp.lang.ada)
  • Re: Houston-related rants was Re: forced merges/inside lane merges/AASHTO "tapered merges"
    ... >> Are you sure about the North Loop and I-45? ... >> in particular the westbound exit for Fondren/Gessner. ... How could HCTRA put an exit ramp for eastbound ... and the West Houston Center Blvd exit still shows Old Westheimer ...
    (misc.transport.road)
  • Re: Strategies with SPARK which does not support exceptions
    ... The only way of interrupting a code sequence in SPARK is the exit ... pass' loop with an unconditional exit at the end. ...    Some complicated code that might set OK; ...
    (comp.lang.ada)