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...
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?
...
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...
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...
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.
...
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...
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?
...
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'
...
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...
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 ...
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 ...
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...
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;
...
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":
...
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 ...
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];
...
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...
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 ...
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 ? */...
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...