would you use a jump statement

Started by
1 comment, last by heron3d 11 years, 10 months ago
I've reached a point is my code where it would be tempting to use a go to: label. Labels have always been frowned upon and this makes me hesitate using them.

I want to make it a habit of writing good code and I'm really at an impasse here. On the one hand, there is the convention and on the other the technical drawbacks. I think if there are no technical drawbacks I would go against convention in this case.

How do you pros feel about labels? And are there any technical drawbacks to using jump statements of this kind?

Thanks in advance
Nikos
Advertisement
There are no technical drawbacks. Maybe jumping in and out of scopes can have effects on automatic objects. The drawback with jump statements is that they make it more difficult to follow the flow of control, adding a risk for something going wrong.

Usually, when resorting to using a "goto", it is an indication that the flow of logic has become too entangled. That is the real problem.

See some interesting thoughts at Goto Considered Harmful. I should add that this is a discussion that can easily turn into a flame war. But most people probably agree that you should avoid goto as much as possible.
[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

See some interesting thoughts at Goto Considered Harmful.

That is funny. His guidelines apply in my case. My goto will point forward and will make my code incredibly more easy to understand and it is only used once.

I've decided. thanks. gamedev.net rocks

This topic is closed to new replies.

Advertisement