-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 07 January 2005 00:17, zentara wrote:
> Like in this contrived example.
>
> foreach  my $x (1..100){
>      foreach  my $y (1..500){
>           foreach  my $z (1..1000){
>               if(  $x + (2 * $y) - $z = 0 ) {goto END}
>      }
>       $y = $x + 1;
>     }
>   $z = $y/4;
> }
> END:
Now, I haven't done this for a while, so I hope I'm correct, but I find this a 
little cleaner:

OUTERLOOP: foreach  my $x (1..100){
      foreach  my $y (1..500){
           foreach  my $z (1..1000){
               if(  $x + (2 * $y) - $z = 0 ) {last OUTERLOOP;}
      }
       $y = $x + 1;
     }
   $z = $y/4;
 }

That way it's a bit clearer what loop you are skipping, which ideally is what 
you are looking at when working on an algorithm, rather than where you jump 
to specifically. It also works better if you name the loops in a nice way 
(hard to do in a contrived example, of course). It achieves exactly the same 
thing as your goto (in probably exactly the same way internally). 

Note that this is just opinion, but it took me a couple of years to undo the 
brain-damage caused by programming exclusively in BASIC when I started 
coding, so I am now of the school that "GOTO considered harmful (unless you 
really really need it, and if you think you do, there is probably a better 
way to do what you are trying to do)"

- -- 
Robin <[EMAIL PROTECTED]>             JabberID: <[EMAIL PROTECTED]>

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0xA99CEB6D = 5957 6D23 8B16 EFAB FEF8  7175 14D3 6485 A99C EB6D
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFB3S6SFNNkhamc620RAtSUAKCh1ZZ2EYZkJqmOLEI9+ZK63FlNCgCghbLA
aUx0bii9rBEXJcrE63dxsfI=
=ZKVm
-----END PGP SIGNATURE-----

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to