The “why not” is not really a reasonably-debatable topic. The reasons for avoiding GOTO are pretty bedrock solid.
The (sociological) problem today began with the highly-opinionated tongue-in-cheek paper “
Goto Considered Harmful” by Edgar Dijkstra. (Yes,
that Dijkstra, who knows a thing or two more about computers than you do.)
The very basis of the paper is this: Dijkstra observed that code using GOTO was typically
less-readable,
less-maintainable, and
less-correct than code that was better-structured. His paper was an effort to drolly shove people in the direction of using more structure in programming.
This basically kicked off the “structured programming” orgy that indoctrinated sheeple to this day.
GOTO is not evil, but it has its place. If you need it*, use it.
The reality is that bad programmers can write bad code with or without GOTO. They are significantly enabled when they are allowed to use GOTO, though.
In the case of the original code, such a use of GOTO has always been gratuitous. An equivalent, but infinitely less brittle construct is to use a
break
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
int main()
{
while (true)
{
std::string input;
getline( std::cin, input );
std::cout << "Input text: " << input << "\n";
if (input == "jump") break;
}
std::cout << "Bye!\n";
}
|
* Chances are pretty close to 1 that you do
not need it.