goto

GOTO still considered harmful?

Everyone is aware of Dijkstra's Letters to the editor: go to statement considered harmful (also here .html transcript and here .pdf) and there has been a formidable push since that time to eschew the goto statement whenever possible. While it's possible to use goto to produce unmaintainable, sprawling code, it nevertheless remains in mod...

Continue Considered Harmful?

Should developers avoid using continue in C# or its equivalent in other languages to force the next iteration of a loop? Would arguments for or against overlap with arguments about Goto? ...

Examples of good gotos in C or C++

In this thread, we look at examples of good uses of goto in C or C++. It's inspired by an answer which people voted up because they thought I was joking. Summary (label changed from original to make intent even clearer): infinite_loop: // code goes here goto infinite_loop; Why it's better than the alternatives: It's specific...

To Use GOTO or Not?

Hi Currently I am working on a project where goto statements are heavely used. The main purpose of goto statements is to have one cleanup section in routine rather than multiple return statements. Like below BOOL foo() { BOOL bRetVal = FALSE; int *p=NULL; p = new int; if(p==NULL) { cout<<" OOM \n"; goto Exit...

Why is goto poor practise?

This question is a duplicate of Goto Still Considered Harmful. If you wish to discuss this further please use the original question. Why exactly is GOTO poor programming practise? It makes sense on some occasions to use it. ...

When is it OK to use the GoTo statement in VB.Net?

I have process that needs to create a bunch of records in the database and roll everything back if anything goes wrong. What I want to do is this: Public Structure Result Public Success as Boolean Public Message as String End Structure Private _Repository as IEntityRepository Public Function SaveOrganization( _ ByVal orga...

SQL GOTO statement using variable label

i was hoping to be able to do something like this: declare @label varchar set @label = 'label_1' goto @label label_1: label_2: of course, sql server gives me an incorrect syntax error... so i was wondering if i can still do this with a slightly different syntax? ...

Naming conventions for GoTo labels

How do you name your GoTo labels? I use rarely often so I'm having a hard time finding good names. Please refrain from the classical 'goto is evil and eat your code alive discussion' ...

Flow controlling macros with 'goto'

Yes, two hated constructs combined. Is it as bad as it sounds or can it be seen as a good way to control usage of goto and also provide a reasonable cleanup strategy? At work we had a discussion about whether or not to allow goto in our coding standard. In general nobody wanted to allow free usage of goto but some were positive about us...

PHP and the goto statement to be added in PHP 5.3

The "goto" statement comes straight out of ASM or any other assembler language. Here's a link: http://be2.php.net/manual/en/control-structures.goto.php I'm wondering: what can this do to make my code more well-organized? How can I implement this in larger projects, without screwing it up. Since the goto will allow you to jump back and ...

Code Curiosity

I was looking at the YUI Compressor and came across this piece of code in the ECMA.NET project (Continuation file if you are interested). protected internal override int FindPrototypeId (string s) { int id; #region Generated PrototypeId Switch L0: { id = 0; string X = null; if ...

Guess this goto label...

I was about to refactor this following VB6 code (written by someone else). Public Function GetValue(ID As Long) As Boolean On Error GoTo eh '' ... DAL Logic... eh_Exit: On Error GoTo 0 Exit Function eh: Resume eh_Exit End Function What do you think the original author's intention was for the label eh? Probably Just "eh, som...

Valid use of goto for error management in C?

This question is actually a result of an interesting discussion at programming.reddit.com a while ago. It basically boils down to the following code: int foo(int bar) { int return_value = 0; if (!do_something( bar )) { goto error_1; } if (!init_stuff( bar )) { goto error_2; ...

VB.NET Switch Statement GoTo Case

I am writing some code in VB.NET that uses a switch statement but in one of the cases it needs to jump to another block. In C# it would look like this: switch (parameter) { case "userID": // does something here. case "packageID": // does something here. case "mvrType": ...

only do if day... batch file

hello i got a batch file, something like this: if %day%==monday, tuesday, wednesday, thursday, friday ( goto yes ) else ( goto no ) Now i know the first line won't work. What i actually want to happen: It automatticly checks which day it is. If it is Monday to Friday, it has to go to 'yes', otherwise (saturday/sunday) to 'no'. How ...

C/C++ goto

Hi everybody! I want to declare an array of "jumplabels". Then I want to jump to a "jumplabel" in this array. But I have not any idea how to do this. It should look like the following code: function() { "gotolabel" s[3]; s[0] = s0; s[1] = s1; s[2] = s2; s0: .... goto s[v]; s1: .... goto s[v]; ...

How to simulate exceptions in C with goto?

I'm writing a concurrent transaction library in C and found the following problem. Let's consider a sample transaction member pseudo-code, where the "transaction" represents a communication channel with the transaction master: transaction = trans_join(); do_some_ops(); /* receive the data from the master */ trans_rcv(transaction, data...

Is there a Java bytecode optimizer that removes useless gotos?

Problem: I have a method that compiles to over 8000 bytes of Java bytecode. HotSpot has a magic limit that makes the JIT not kick in for methods that exceed 8000 bytes. (Yes, it is reasonable to have a huge method. This is a tokenizer loop.) The method is in a library and I don't want to require users of the library to have to configure ...

Use C switch statement for error handling

Consider this C construct that checks for errors before doing actual work: int function(struct Context *context,struct Connection *conn) { int retval; switch(0) { case 0: retval = BUFFER_INACTIVE; if(conn->mSocket == -1) break; retval = BUFFER_FULL; /* Is there enough room to add ? */...

How could I rewrite this to remove the gotos without loss of speed or readability?

I wrote this. Yes, I know it's VB6. Yes, it is production code, and, yeah, I know it uses gotos. I am a lazy, evil beast ... So show me (and the rest of us) how it should be written Public Function SplitString(ByVal sText As Variant) As Variant Dim nHere As Long Dim cHere As String * 1 Dim aRes As Variant Dim nRes As L...