goto

GOTO still considered harmful? [closed]

a 夏天 提交于 2019-11-28 13:06:36
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . 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

VB.NET Switch Statement GoTo Case

风格不统一 提交于 2019-11-28 11:53:15
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": if (otherFactor) { // does something here. } else { goto default; } default: // does some processing... break; } However, I don't know how to convert this to VB.NET. I tried this: Select Case parameter Case "userID" ' does something here. Case "packageID" ' does something here. Case "mvrType" If otherFactor Then ' does something

is erlangs recursive functions not just a goto?

久未见 提交于 2019-11-28 10:03:22
Just to get it straight in my head. Consider this example bit of Erlang code: test() -> receive {From, whatever} -> %% do something test(); {From, somethingelse} -> %% do something else test(); end. Isn't the test() call, just a goto? I ask this because in C we learned, if you do a function call, the return location is always put on the stack. I can't imagine this must be the case in Erlang here since this would result in a stackoverflow. In basic. We had 2 different ways of calling functions: goto and gosub. goto just steered the program flow somewhere else, and gosub remembered where you

Using Goto function across different functions

早过忘川 提交于 2019-11-28 07:01:56
问题 How can I use goto function across different functions .For ex , main() { .... REACH: ...... } void function() { goto REACH ; } How to implement such usage ? 回答1: You can't in Standard C++. From $6.6.4/1 of the C++ Language Standard The goto statement unconditionally transfers control to the statement labeled by the identifier. The identifier shall be a label (6.1) located in the current function. ...or in Standard C. From $6.8.6.1/1 of the C Language Standard The identifier in a goto

Is there ever a reason to use goto in modern .NET code?

末鹿安然 提交于 2019-11-28 06:16:44
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression != null) { this._PasswordStrengthRegularExpression = this._PasswordStrengthRegularExpression.Trim(); if (this._PasswordStrengthRegularExpression.Length == 0) { goto Label_016C; } try { new Regex(this._PasswordStrengthRegularExpression); goto Label_016C; } catch (ArgumentException exception) { throw new ProviderException(exception.Message, exception); } } this._PasswordStrengthRegularExpression = string.Empty; Label_016C: ... //Other stuff I've heard all of the "thou shalt not use goto

How to use goto statement correctly

偶尔善良 提交于 2019-11-28 04:32:22
I am taking my high school AP Computer Science class. I decided to throw a goto statement into a one of our labs just to play around, but I got this error. Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "goto", assert expected restart cannot be resolved to a variable at Chapter_3.Lab03_Chapter3.Factorial.main(Factorial.java:28) I went to a goto question on Stackoverflow to find out how to do it properly, and I did exactly as was demonstrated in one of the answers. I really don't understand why the compiler wants an assert statement (at least

Better way to write retry logic without goto [duplicate]

两盒软妹~` 提交于 2019-11-28 03:41:55
问题 This question already has an answer here: Cleanest way to write retry logic? 27 answers Is there a better way to write this code without using goto ? It seems awkward, but I can't think of a better way. I need to be able to perform one retry attempt, but I don't want to duplicate any code. public void Write(string body) { bool retry = false; RetryPoint: try { m_Outputfile.Write(body); m_Outputfile.Flush(); } catch (Exception) { if( retry ) throw; // try to re-open the file... m_Outputfile =

C/C++: is GOTO faster than WHILE and FOR?

青春壹個敷衍的年華 提交于 2019-11-28 01:53:30
I know, that everybody hates GOTO and nobody recommends it. But that's not the point. I just want to know, which code is the fastest: the goto loop int i=3; loop: printf("something"); if(--i) goto loop; the while loop int i=3; while(i--) { printf("something"); } the for loop for(int i=3; i; i--) { printf("something"); } Gabe Generally speaking, for and while loops get compiled to the same thing as goto , so it usually won't make a difference. If you have your doubts, you can feel free to try all three and see which takes longer. Odds are you'll be unable to measure a difference, even if you

Is there goto statement in Ruby?

自闭症网瘾萝莉.ら 提交于 2019-11-28 01:48:48
Is there a way to start at a specified line, like a goto statement? First, it would be statement, not a command. Second, see ruby-goto . Third, note Category: Library/Evil DigitalRoss There is the ruby command line switch -x . -x[directory] Tells Ruby that the script is embedded in a message. Leading garbage will be discarded until the first that starts with “#!” and contains the string, “ruby”. Any meaningful switches on that line will applied. The end of script must be specified with either EOF, ^D (control-D), ^Z (control-Z), or reserved word __END__. If the direc‐ tory name is specified,

C : stack memory, goto and “jump into scope of identifier with variably modified type”,

こ雲淡風輕ζ 提交于 2019-11-28 01:47:53
I found that this refuses to compile : int test_alloc_stack(int size){ if(0) goto error; // same issue whatever conditional is used int apply[size]; give_values(apply,size); return 1; error: return 0; } The error I get is : "jump into scope of identifier with variably modified type". Eliminating the line with "goto" and the jump to error solves the issues. If I use dynamic allocation for apply, then the problem also disappear. This compiles fine: int test_alloc_heap(int size){ if(0) goto error; int * apply = calloc(sizeof(int),size); give_values(apply,size); free(apply); return 1; error :