Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Number of times I've used goto in Perl

by Anonymous Monk
on Apr 13, 2002 at 05:08 UTC ( #158738=note: print w/replies, xml ) Need Help??

in reply to Number of times I've used goto in Perl

Most people don't use goto because they don't know how. As a Cobol programmer, I use it all the time. I will use it in perl if I feel they need. Sometimes, it's better than having long loops where you can easily get confused. A nice goto can simplify things, but you have to know how to use it properly so you don't get in to endless loops. If you use a goto, you just have to make sure that you never return to that code and if you do that you get out properly. To those that say goto is poor programming, I say BS.
  • Comment on Re: Number of times I've used goto in Perl

Replies are listed 'Best First'.
Re^2: Number of times I've used goto in Perl
by Anonymous Monk on Jun 16, 2009 at 21:37 UTC
    I quite agree. The first language I ever learned was a rather primitive dialect of BASIC. There were no block IF statements, no NEXT, LAST, CONTINUE etc for while loops. The only branch commands were GOTO and GOSUB. One can write very clear, very well-structured code with GOTOs. However, the structure must be self-imposed since the language will not force you to write in a well-structured fashion. Saying that GOTO causes messy code is like saying that hammers cause squashed thumbs.

    The best description I have heard is that GOTO is like a stick of dynamite. Occasionally, when programming, you come across a large boulder in the middle of your path. While you *can* build an elaborate structure to go around it, it is often faster and more efficient to just blow it up. Just be careful not to bury yourself under tons of rubble when doing so.

    The other place to use a goto is anyplace you find yourself intentionally building an infinite loop. If you use a while(1) kind of construct, you are necessarily wasting CPU cycles evaluating a conditional which is always true. Building such a loop with GOTOs is just as easily readable, and more efficient.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://158738]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2019-10-15 16:21 GMT
Find Nodes?
    Voting Booth?