Is it ok to use lots of goto statements?

Hi guys... i'm new to this site, and i really wanted to learn even deeper. I'm confused if how to identify a beginner or not.. But anyways, I wanted to ask if is it ok to use several goto statements, because I created a simple game but I noticed there were many goto statements, is this ok? or never been ok? please help! :(
Last edited on
It is perfectly ok - as long as you are convinced that the gotos make your code more readable and maintainable.
It's valid but I wouldn't advise it.

If there's another way (and there usually is) then I would avoid goto all together.

Take a look at control statements: http://www.cplusplus.com/doc/tutorial/control/

To avoid this: http://en.wikipedia.org/wiki/Spaghetti_code

Last edited on
Even to use only one goto statement is very bad and that says about the programmer that he is of very low qualification!
C/C++ programmer shall forget that there is the goto statement in C/C++.
oh.... thanks! that's better... :D one more thing... I used the procedural way of programing and never been yet too familiar on OOP... Is it ok? or do I really need to learn OOP?
procedural: learn a BASIC like language or go with strict C
OOP: go with C++ and use object oriented concepts. Just a few parts of your code should be procedural outside an object oriented scope.

IMO
Last edited on
OOP is not a set of some syntactical constructions as someone can think. It is the mode of thought. You can write OOP programs even in C where there is no such a set of syntactical constructions.:)
Last edited on
Avoid goto under all circumstances. If you feel like using goto your code is already a mess.

do I really need to learn OOP?
Yes you need to learn it. Today you won't get far without it even on embedded systems such as smartpones
Then I just have to remove all gotos and revise it... Thanks guys! Now I know why... I had this teacher who uses several gotos in his/her program, and I read an article about gotos that it's never been cool using it and I became confused... now I know. :D
I had this teacher

Many teachers who have to teach you/us programming aren't experienced enough to do it the right way. They have learned programming in the 80's/90's with languages like GWBasic or something like that. And this is not the current state of technology ;o)
closed account (1vRz3TCk)
Learn how to use it properly and use it properly.

You will find that people say avoid it at all costs. I would say don't look to it as your first solution, there are often better ways, but don't fear it.
Your exposure to OOP will really depend on where you are in programming right now.

If you've not come across classes and the like yet, then you'll have had little much do to with it. When you start playing with classes and, in turn, utilise principles such as encapsulation, inheritance and polymorphism you'll then start to understand the benefits of OOP.
Last edited on
I had this teacher who uses several gotos in his/her program
Be careful with such a teacher. People don't like to hear that they produce messy code especially when it's true...
Topic archived. No new replies allowed.