Template:Computer Programming/Control/5

Isn't goto evil?Edit

One often hears that goto is evil and one should avoid using goto. But it is often overlooked that any return which is not the last statement inside a procedure or function is also an unconditional statement — a goto in disguise. There is an important difference though: a return is a forward only use of goto. Exceptions are also a type of goto statement; worse, they need not specify where they are going to!

Therefore if you have functions and procedures with more than one return statement you can just as well use goto. When it comes down to readability the following two samples are almost the same:

Last modified on 28 September 2009, at 16:57