hello
I have changed title slightly because I thought this is more appropriate question.
Would you refactor it (seems like legitimate use of goto) ?
If, how would you refactor the following code to remove go to statement?
if (data.device) {
try {
...
}
catch(const std::exception&) { goto done; }
... // more t...
I have run across the following pattern a few times while developing Perl modules that use AUTOLOAD or other subroutine dispatch techniques:
sub AUTOLOAD {
my $self = $_[0];
my $code = $self->figure_out_code_ref( $AUTOLOAD );
goto &$code;
}
This works fine, and caller sees the correct scope.
Now what I would like to do ...
Possible Duplicate:
GOTO still considered harmful?
I just came across some C# code that had a goto statement in it (which I didn't even know C# supported). I only vaguely remember hearing about goto statements in one of my college classes. I seem to remember my professor saying it should never be used but I don't remember wh...
Possible Duplicates:
Why is it bad to use goto?
GOTO still considered harmful?
I was ramdomming through xkcd and saw this one (if also read some negative texts about them some years ago):
What is actually wrong with it? Why are goto's even possible in C++ then?
Why should I not use them?
...
I'm writing a console based application that prompts a user for a series of questions. E.g:
"Enter a record to open:"
"Do you want to do X?"
"Do you want to do Y?"
"Are you sure you want to continue?"
If the user enters nothing at any prompt I want to go up one level. This is easy using goto. The only other way I can think of to do...
To start with I'll say that I agree that goto statements are largely made irrelevant by higher level constructs in modern programming languages and shouldn't be used when a suitable substitute is available.
I was re-reading an original edition of Steve McConnell's Code Complete recently and had forgotten about his suggestion for a commo...
Hi,
I am studying this code sample:
class Program
{
static void Main(string[] args)
{
int x = 10;
int y = 10;
int generate=0;
string [,] myArrayTable = new string[x, y];
Console.WriteLine("Enter a seek number: ");
string cautat = Console.ReadLine();
for (int i = 0; i <...
Hi,
I know using goto is something most people say to avoid, however I have read on various places that sometimes it is useful if you need simple code.
Currently I have very simple program that needs to be repeated if user selects so:
static void Main()
{
Restart:
...
string UserChoice=Console.ReadLine();
if (UserChoice...
I need to exit a SQL script without an error if a certain condition holds true. I've read that 1 solution would be to raiseerror with error code 20+ and with log parameter. But the limitation for that is that i can execute that only as an admin and the connection to the db will be aborted.
Also, I tried using GOTO and jump to the end-o...
Alright, so you have a TObjectList instance. You want to loop through the items in it and delete some of the objects from the list. You can't do this:
for I := 0 to ObjectList.Count - 1 do
if TMyClass(ObjectList[I]).ShouldRemove then
ObjectList.Delete(I);
...because once you delete the first object the index counter I will be al...
The following is pseudocode:
myGoto:
try
{
// do some db updating
myDB.doOptimisticConcurrency();
} catch (MyConcExeption ex) {
if (tried < fiveTimes) {
myDB.Refresh();
tried++;
goto myGoto;
}
}
I have several try-catch blocks in one method, and I don't want to reinvoke my method from the beginning ...
Hello all,
I have a problem with GOTO command and affiliated labels.
Facts: Given a bunch of files from a folder (they are log errors) I need to open them and check if they contain a specific string. If yes then eliminate some characters (all the chars after the last appearance of "_", including itself) from the file names and do othe...
Hello, I have always been taught almost never to use goto statements in programming, however we are required to do so as part of my most recent programming project. I have an if/else statement with various goto statements, and the goto statements are failing to execute. I have no idea why. Any help would be appreciated.
int myInt...
Hello!
I have a code for updating my application resources to current application version.
This code is called after application update.
int version = 1002; // current app version
switch(version)
{
case 1001:
updateTo1002();
goto case 1002;
case 1002:
updateTo1003();
goto case 1003;
case 1003:
...