there is something i dont get (C# )

what dose Goto mean in C#?

The same as in most other languages - that you'll generally get a slap for using it :P

"The goto statement transfers the program control directly to a labeled statement"

http://msdn.microsoft.com/en-us/library/13940fs2(VS.71).aspx

The reason we're giving you such a hard time about goto is that it has a long history in Computer Science as a bad programming method. You do need transfer of control capability of course, but goto lets you transfer control to anywhere in your program, which can be very confusing when trying to figure out a bug or trying to understand someone else's code.

You can get by in almost all situations with "structured" control statments: while, if-then-else, for, switch, break, continue, return, yield, throw

These are structured because they sort of turn your program into an "outline" where statements control only more deeply nested blocks of code that appear immediately after it inside {...}. There are very few places where goto is actually needed (some would say there are no places). If you think you really need goto, then go ahead and use it, but most likely you could reorganize your code to make it understandable and modular by avoiding goto.

"In 1978, Berkeley scientists did a study on the effects of GoTo on rats. Twenty rats in a control group were fed a normal diet, while twenty other rats were forced to program in Apple BASIC. Their health was to be monitored for a month, but after two weeks all of the rats in the programming group had melted into a dense goo that tasted a little like quiche. " GoTo considered harmful

Goto is short for "Gotoga" (or go-Toga) which is a sideways reference to the 1978 cult classic "Animal House" starring John Belushi. Use of "goto" in programming languages (such as C#) means that you are thumbing your nose at established and accepted programming design principles and just doing your own "thing". Language designers of course are all aging hippie types themselves, and left "goto" in the language as a sort of homage to the anti-establishment sentiment. By using goto in your own programs you are making a stand against the "man" and keeping hippie culture alive in our modern connected world without raising the ire of your bosses or marketing types who will never know what it means.

as others said goto allows you to transfer the flow of the program to another location and continue from there.

people say that it's not a good practice to use goto but there are situations that it can be really useful. guys it's game programming and performance is the king, forget about OO completely and sometimes go and hate structural programming too.

use goto in these scenarios specially if you code for mobile devices.

  1. if you want to go outside of deeply nested loops (like the msdn page's example)
  2. if the code is running by multiple objects and every frame and you want to avoid loop's condition checking or function calls. usually the difference would be small but it's sometimes important in mobile devices.
  3. in switch case statements when you want to jump to another case which again can be really handy sometimes.

saying this, i should say that i used goto a few times in my coding life but in those situations it was really useful. if you are not sure then you can test your code with goto and with other methods like function calls.

when i said using goto instead of loop i meant loops like while(true) that you break later using something.

C# programming 101: Dont ever use Goto!

Well you can if you really want to but its not good practice. It should only be used to get out of deeply nested loops. Otherwise its good practice to not use Goto at all. Trust me, your life will be better for it :)

so Dont use goto?