Saturday, December 30, 2006

Goto

It has always been suugested to not use Goto in our programs, instead use for while and other stuff like it. why??

firstly, using goto may insert labels into the program and when we encounter a label at a particular place in the program, it becomes very difficult to say from where might have the control landed up there. It makes the understanding of the difficult and hence the debugging gets even tougher.

secondly, using constructs like for, while makes the program somewhat structured and its easy to trace the flow of control withinn the code... also using these constructs maps the code to real world scenario where a conditional statement may be represented as an decision and a for while may be regarded as repeating sometimes over and over.... but what does Goto represent in real world scenario??

Thirdly, making use of too much Goto may result in speghetti code . There is also a story associated with goto. have a look.

No comments: