RE: GOTO statement and return results way
- From: Roger Tranchez <run1789@xxxxxxxxxxxxxxxx>
- Date: Mon, 14 Jan 2008 04:48:01 -0800
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.
- Follow-Ups:
- Re: GOTO statement and return results way
- From: Stephany Young
- Re: GOTO statement and return results way
- References:
- GOTO statement and return results way
- From: Roger Tranchez
- RE: GOTO statement and return results way
- From: AMercer
- GOTO statement and return results way
- Prev by Date: RE: GOTO statement and return results way
- Next by Date: Re: Preventing the power option Turn off Monitor?
- Previous by thread: RE: GOTO statement and return results way
- Next by thread: Re: GOTO statement and return results way
- Index(es):
Relevant Pages
|