Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Goto Statement ! is it bad ?

Status
Not open for further replies.

Neveth

Newbie level 6
Joined
Aug 17, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Coimbatore, India
Activity points
1,372
i heard that using 'goto' statement in c codings is not good. And it is not preferable. Is it so ? Is that any particular/technical reason about avoiding goto ?
 

Why would you use the 'goto' statement? There so many other ways to do you job!! I think that -almost- all cases of 'goto'-statement usage could be replaced with other solutions!

For me, 'goto' statement can lead to a code that is not very easy to be read and this could possibly make you not being able to recognize and solve potential problems. I think it is just a matter of code organization.
 

I think that -almost- all cases of 'goto'-statement usage could be replaced with other solutions!
In a complex code, after solving the almost cases, you possibly keep one or two, that suggest to use goto as the obviously most straightforward solution...

How to break e.g. from a multi-level case structure to the outer level? You can either use additional flag variables (waste resources) or a goto. In C++. you have exceptions as a possible alternative, but most likely at the expense of increased resource usage.

But I agree, that goto should be a treated as a last ressort, if no equivalent structurized C statement can be found.
 

In a complex code, after solving the almost cases, you possibly keep one or two, that suggest to use goto as the obviously most straightforward solution...

How to break e.g. from a multi-level case structure to the outer level? You can either use additional flag variables (waste resources) or a goto.

Of course, of course... you have absolutely right for the example that you just gave. I didn't intend to insult anyone! ;) But these cases can only be found at high level programs. Isn't that correct?
 

Isn't that correct?
Absolutely. I also agree, that you should mainly aim to clear structure and code readability. Thinking in basic C structures should be emphasized, particularly when learning programming. Goto is just a supplement for special cases.
 

Hi,

"goto" make your c code messy and not well structure, that i think is the main reason to avoid it.
There are many way to re-write your code and avoid goto completely which one has to learn.

Regards,
Tom
 

You can use GOTO and there are many cases when GOTO is the only one solution. Keep in mind that in more of the cases you can completely avoid GOTO, in fact it's hard to find an example which can't be solved without GOTO. If you're beginner in C I would recommend you to avoid GOTO, once you have enough experience you can violate this rule and use very carefully GOTO in some rare cases where code without GOTO looks messy.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top