Jump to content

Reliability of goto


dotkpay

Recommended Posts

Hello,

I just started using the new feature of php 5 "goto" that skips a bunch of code to a labeled point. But how reliable is goto. I was advised by a programmer to avoid it. Should this be the case? My concern is about its reliability because I currently use it very often in my new projects. Can it cause any form errors in files?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/
Share on other sites

The problem with 'goto' is that it leads to spaghetti code - code that jumps from place to place, all layered and threaded with other such code.  This makes the code hard to read, hard to edit, and hard to debug.  Using 'goto' is a clear indication of bad design, and generally doing things wrong.

 

Well formed code does not use 'goto'.

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233963
Share on other sites

Is there an alternative to "goto", how else can I skip code?

 

What do you mean "skip code"?  If you don't need to execute it then don't put it there.  If you may sometimes need to execute it based on a condition, then use an IF or SWITCH with that condition.  Or you can conditionally call a function that contains that code.  For virtually any example you post, we can give you a better way than goto I'm sure.

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233979
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.