It isn't. True, you can write bad code with goto, but you can do that without goto as well.
He considered the "goto" statement to be harmful.
goto is a statement, not a programming style.
AGAIN: puts ("c"); goto AGAIN;
A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:return return-type;A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:goto label_name;....label_name: statements;
The goto statement.
Statement goto is not allowed.
A 'goto' statement immediately moves the execution of code to another part of the program. This makes the code difficult to follow and to debug. It is better practice to use If-then-else constructs to structure the program code.
The goto statement is a control flow statement that causes the CPU to jump to another spot in the code. This spot is identified through use of a statement label. The following is an example of a goto statement and statement label:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> #include <cmath> int main() { using namespace std; tryAgain: // this is a statement label cout << "Enter a non-negative number"; double dX; cin >> dX; if (dX < 0.0) goto tryAgain; // this is the goto statement cout << "The sqrt of " << dX << " is " << sqrt(dX) << endl; }
int main (void) { puts ("Hello"); goto LABEL; LABEL: return 0; }
while, for, do-while (and perhaps goto)
The short answer is that goto statements generally cause messy and hard to read code. This reduces the ability to update that code. Also it was proven that nearly everything that goto was used for could be done using other control statements like the while loop or function calls. for a more informative answer go here http://www.cs.utexas.edu/~EWD/transcriptions/EWD02xx/EWD215.HTML
Because the use of GOTO creates code that jumps all over the place, and is hard to read and follow, often referred to as "spaghetti code".