Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Goto statement.

Status
Not open for further replies.

Wulfdog

MIS
Feb 19, 2001
88
US
I am going through someone elses code, and have a simple question I want to clarify. I am kind of new to it...

It is a simple goto statement.

In the main program, in a couple of nested for loops, there are a couple of goto statements that are executed only if certain criteria are met. If it is met, the goto statement says "goto S;" When it is executed, it skips any code between that goto statement and S, right? What I am saying is, after S is completed, it doesn't jump back up and contines where the goto S was.

If the goto statements don't get reached, but the main program continues, when it reaches S:, does it perform S:?

I believe so...I think that I am getting my Goto's and functions mixed up.

Hope I make some sense :)

Thanks.

Nick
 
Hi Nick,

All your assumptions are true. And when the main program gets to S:, it does perform S:. CaKiwi
 
Try to avoid goto.
Personaly I use goto only to jump to the end of function in case if error status has been returned by one of the called function and I am checking all locally allocated memory and free it if neccesary before living the function. To use it you have to initialize all you pointers by NULL and at the end of function check if it is not NULL then free it. This will help to avoid memory leaks and do not have problem with woid pointers. In this case mine functions have only one return status and I don't have to use free() before each return.
This is probably the only case when goto makes program more understandable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top