Viewing a single comment thread. View all comments

trutheality t1_iybj9ay wrote

Control structures like if/else statements, while loops, and for loops place the code that is executed when the condition is true or false in predictable places, and more importantly, (unless there was an early return or a thrown exception), the control flow always returns to the line after the end of the (for example if/else) block when the conditional part is done. Goto has no such guarantees: it could send you to some arbitrary line earlier or later in the code and the only way to figure out if you ever come back is to go see if some other goto sends you back. Using gotos also means that there could be parts of your code that don't really make sense unless you know what gotos send you there.

As a result, gotos can make your code very hard to understand by inspection, and it also means that it's easier to make mistakes when writing code with gotos. That's not to say that it would be impossible to write readable code with gotos, but if you put all your conditional logic in predictable patterns, you're probably structuring it the same way you would using if or while statements anyway.

1