Senger CodeLab 🚀

GOTO still considered harmful closed

September 29, 2026

📂 Categories: Programming
GOTO still considered harmful closed

Is GOTO still considered harmful? Edsger Dijkstra’s infamous 1968 letter sparked a debate that continues to resonate in software development circles. While the landscape of programming has evolved significantly, the core concerns about code clarity, maintainability, and debugging persist. This article delves into the relevance of Dijkstra’s arguments in modern programming, exploring the contexts where GOTO statements might still be problematic and examining alternatives that promote cleaner, more robust code.

The Legacy of Dijkstra’s Argument

Dijkstra argued that the unrestricted use of GOTO statements leads to “spaghetti code”—a tangled mess of jumps and branches that makes understanding and modifying programs incredibly difficult. He advocated for structured programming, emphasizing clear control flow constructs like loops and conditional statements. This laid the foundation for modern programming practices, influencing the design of numerous languages.

His letter highlighted the negative impact of GOTO on program comprehension, making it harder to reason about the execution flow and trace bugs. This, in turn, increases development time and the likelihood of errors.

The impact of Dijkstra’s letter was profound, leading to a shift away from GOTO in favor of structured programming paradigms. Many modern languages discourage or even eliminate GOTO entirely.

GOTO in Modern Programming Languages

Many contemporary languages like Java and Python omit GOTO altogether, reflecting the prevailing preference for structured programming. However, some languages, including C and C++, still retain GOTO, primarily for low-level operations or specific performance optimizations.

Even in these languages, its use is generally discouraged except in very niche circumstances, such as error handling or breaking out of deeply nested loops, where structured alternatives might be less efficient or cumbersome.

For instance, in embedded systems or performance-critical sections of code, GOTO can occasionally offer marginal performance gains, although this is often at the expense of readability.

Alternatives to GOTO

Structured programming provides a robust set of tools for controlling program flow without the need for GOTO. Loops (for, while), conditional statements (if, else), and function calls offer clear, predictable ways to manage execution paths.

These constructs promote modularity and readability, making code easier to understand, debug, and maintain. They also facilitate code reuse and collaboration among developers.

Modern languages further enhance control flow with features like exceptions and iterators, offering more elegant and powerful solutions to problems that might have tempted programmers to use GOTO in the past.

When GOTO Might Still Be Considered

While generally discouraged, some highly specialized scenarios may warrant the use of GOTO. For example, in certain low-level programming tasks or when interacting directly with hardware, GOTO can provide a direct and efficient way to manipulate control flow. This is particularly relevant in embedded systems or operating system development.

Furthermore, in some limited cases involving deeply nested loops or complex state machines, using GOTO can potentially simplify the code compared to structured alternatives. However, such situations are rare and should be carefully considered against the potential impact on code readability.

It’s crucial to weigh the benefits against the potential downsides to readability. Even in these specialized cases, careful documentation and justification are essential to ensure that the code remains maintainable.

  • Structured programming is preferred in most cases.
  • GOTO can be problematic for readability and maintainability.
  1. Analyze the specific use case.
  2. Consider structured alternatives first.
  3. If using GOTO, document and justify its use.

“The use of GOTO statements is detrimental to program structure and readability.” - Edsger Dijkstra, “Go To Statement Considered Harmful”

Consider a scenario where a deep error occurs within a nested loop in a C program. Using GOTO to exit the loops immediately could be more efficient than multiple break statements, but this must be balanced against the reduced readability.

Learn more about structured programmingFeatured Snippet: While GOTO statements can offer minor performance advantages in very specific, low-level scenarios, their use is generally discouraged due to their negative impact on code readability and maintainability. Structured programming constructs provide superior alternatives for managing control flow in most situations.

  • Exceptions are a powerful tool for handling errors gracefully.
  • Iterators simplify working with collections of data.

Go To Statement Considered Harmful

Structured programming

Edsger W. Dijkstra

Infographic Placeholder: A visual representation contrasting spaghetti code with structured code.

Frequently Asked Questions (FAQ)

Q: Is GOTO ever used in modern programming?

A: While discouraged, GOTO can still be found in some low-level or performance-critical contexts, but structured programming offers better alternatives in most cases.

In conclusion, while the specific context of Dijkstra’s original argument might feel dated, the underlying principles regarding code clarity and maintainability remain highly relevant. While extremely niche scenarios might justify the use of GOTO, modern programming best practices emphasize structured programming and its clear, predictable control flow constructs. Explore resources on structured programming and modern software development methodologies to further enhance your coding skills and create robust, maintainable applications. Consider revisiting your own code and identifying areas where structured alternatives could replace any lingering GOTO statements, improving readability and maintainability. Dive deeper into the principles of clean code and discover how these techniques can significantly impact the quality and longevity of your software projects.

Question & Answer :

Everyone is aware of Dijkstra's [Letters to the editor: go to statement considered harmful](http://portal.acm.org/citation.cfm?doid=362947) (also [here](http://www.cs.utexas.edu/%7EEWD/transcriptions/EWD02xx/EWD215.html) .html transcript and [here](http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF) .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 [modern programming languages](http://msdn.microsoft.com/en-us/library/13940fs2(VS.71).aspx). Even the advanced [continuation](http://en.wikipedia.org/wiki/Goto#Continuations) control structure in Scheme can be described as a sophisticated goto.

What circumstances warrant the use of goto? When is it best to avoid?

As a follow-up question: C provides a pair of functions, setjmp() and longjmp(), that provide the ability to goto not just within the current stack frame but within any of the calling frames. Should these be considered as dangerous as goto? More dangerous?


Dijkstra himself regretted that title, for which he was not responsible. At the end of EWD1308 (also here .pdf) he wrote:

Finally a short story for the record. In 1968, the Communications of the ACM published a text of mine under the title “The goto statement considered harmful”, which in later years would be most frequently referenced, regrettably, however, often by authors who had seen no more of it than its title, which became a cornerstone of my fame by becoming a template: we would see all sorts of articles under the title “X considered harmful” for almost any X, including one titled “Dijkstra considered harmful”. But what had happened? I had submitted a paper under the title “A case against the goto statement”, which, in order to speed up its publication, the editor had changed into a “letter to the Editor”, and in the process he had given it a new title of his own invention! The editor was Niklaus Wirth.

A well thought out classic paper about this topic, to be matched to that of Dijkstra, is Structured Programming with go to Statements, by Donald E. Knuth. Reading both helps to reestablish context and a non-dogmatic understanding of the subject. In this paper, Dijkstra’s opinion on this case is reported and is even more strong:

Donald E. Knuth: I believe that by presenting such a view I am not in fact disagreeing sharply with Dijkstra’s ideas, since he recently wrote the following: “Please don’t fall into the trap of believing that I am terribly dogmatical about [the go to statement]. I have the uncomfortable feeling that others are making a religion out of it, as if the conceptual problems of programming could be solved by a single trick, by a simple form of coding discipline!”

XKCD’s GOTO Comic

A coworker of mine said the only reason to use a GOTO is if you programmed yourself so far into a corner that it is the only way out. In other words, proper design ahead of time and you won’t need to use a GOTO later.

I thought this comic illustrates that beautifully “I could restructure the program’s flow, or use one little ‘GOTO’ instead.” A GOTO is a weak way out when you have weak design. Velociraptors prey on the weak.