The usual statement that goto's shouldn't be used because it might be hard for others to follow where it leads to, or because it makes your code look messy, doesn't convince me at all. I could call a function that is like a million lines away from it's caller. Wouldn't that be hard to follow too? Does anyone keep the functions close together so that if someone wants to read the code can find them quickly? Eck, sounds stupid. Ctrl + f does the trick.
The 'rule' (if we can call it that) says that goto gives bad programming habits. You CAN use it, of course. But you should avoid it. Goto is very tricky. It seems harmless and many people are used to using it on other languages (some of them give you no choice). You may exit a loop with a goto if it'll help you. Just make sure you're using it right. Use it to go to a near place, where you can easily see that you're not messing with the process' state. You should avoid it because if you get used to it you may end up using it in other, more complex, situations, where altough it might seem harmless, in fact you're screwing the program's internals. It might be very hard to spot the problem. Compilers won't help you verify if a goto makes sense. Search google for some real-world examples. It's true.
I've used a lot of goto's on some languages, but very few on C and none in C++. I know it might get me to trouble so i supose i'm doing the right thing avoiding it. But hey, don't erase it from C or C++ 'cause you never know, I might need it tomorrow.
Blew
[edited by - Blew on December 18, 2002 2:13:37 AM]