Possible Duplicate:
GOTO still considered harmful?
I have read articles that advise on refraining from using the goto operator frequently, but never told why. I have googled this for ever and can’t really find anything.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
GOTOwas often used frequently in situations that produced “spaghetti” code. In other words, to follow the logic of the code required you to move frequently from point to point, often in an unstructured or unobvious way. This lead to code that was difficult to understand.But in the old days (early BASIC),
GOTOwas often the only way to do iteration so there wasn’t always a choice. More expressive languages provided other ways of doing iteration (for,do ... until,whileand so forth) where the loop was far more obvious.Having said that, it’s really the overuse of
GOTOthat’s considered harmful. It still has its place in many situations such as error handling or finite state machines, provided it doesn’t make the code too hard to follow.