Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

7. C# Language, Part 3: Intransitive Verbs > How Not to Use Goto

How Not to Use Goto

One of the reasons the goto statement gets such a bad rap is that older languages didn’t support conditional iteration. For example, without a do command, you’d have to do something like the following:

TopOfLoop:
x++;
if (X < 5)
 goto TopOfLoop;

That sample isn’t too bad; you can understand what it’s supposed to be doing fairly easily, but the other problem with the goto in older languages is that you could goto anywhere you wanted to stick a label. All too often the result was code that took hours to decipher, assuming you could figure it out at all. If you ever find yourself having to wonder where a goto statement leads, you can be pretty sure you’re not looking at tight, well-written code; you’re looking at a plate of spaghetti. Fix it.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint