Historical context:. We must remember that Dijkstra wrote Goto Wased Harmful in 1968, when many programmers used goto as a replacement for structured programming ( if , while , for , etc.).
It is 44 years later, and it is rare to find this use of goto in the wild. Structured programming has long won.
Case Analysis:
Sample code is as follows:
SETUP... again: COMPUTE SOME VALUES... if (cmpxchg64(ptr, old_val, val) != old_val) goto again;
The structured version is as follows:
SETUP... do { COMPUTE SOME VALUES... } while (cmpxchg64(ptr, old_val, val) != old_val);
When I look at the structured version, I immediately think, "This is a cycle." When I watch the goto version, I think of it as a straight line with the argument βtry againβ at the end.
The goto version has both SETUP and COMPUTE SOME VALUES in the same column, which emphasizes that most of the time the control flow goes through both. The structured version puts SETUP and COMPUTE SOME VALUES in different columns, which emphasizes that control can go through them differently.
The question is, what emphasis do you want to put in the code? You can compare this with goto for error handling:
Structured version:
if (do_something() != ERR) { if (do_something2() != ERR) { if (do_something3() != ERR) { if (do_something4() != ERR) { ...
Go to version:
if (do_something() == ERR) // Straight line goto error; // | if (do_something2() == ERR) // | goto error; // | if (do_something3() == ERR) // | goto error; // V if (do_something4() == ERR) // emphasizes normal control flow goto error;
The generated code is basically the same, so we can consider it as a typographical problem, such as indentation.