in reply to Re: GOTO or not GOTO
in thread GOTO or not GOTO
Imagine you had written:Now my question is what happened to $j there? Is the compiler "smart enough" to know that I exited the loop and therefore the memory allocated to $j can now be reclaimed?for ( my $i = 0; $i < 10; $i++ ) { my $j = $i; if ( $i == 5 ) { goto newlocation; } } newlocation: print( "jumped out" );
you have code that does exactly the same. I presume you have the same worries about $j, and will hence decide to never use 'last'?for ( my $i = 0; $i < 10; $i++ ) { my $j = $i; if ( $i == 5 ) { last; } } print( "jumped out" );
Or else, could you indicate why you have worries about the first construct, but not the last?
Even worse, what happens when I use goto to jump between subroutines?Had you actually bothered to read past the first sentence of the document you link to, you would have known the answer. Here's the second sentence of the document: It may not be used to go into any construct that requires initialization, such as a subroutine or a foreach loop.
It is because I don't know the answers to these questions that I do my best to avoid the use of gotoSince I've now answered the questions, are you now going to start using goto?
I have to admit, you weren't arguing against the use of goto in particular. You were arguing against using constructs you don't know the details about. That's a smart thing. The wise thing would be to actually learn about them instead of bragging ones ignorance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: GOTO or not GOTO
by monarch (Priest) on Jan 27, 2009 at 12:24 UTC | |
by JavaFan (Canon) on Jan 27, 2009 at 12:37 UTC |