in reply to Re: Not Using So Many 'if' Statements
in thread Not Using So Many 'if' Statements

exit is not really the to be preferred way of leaving a loop, as it completely exits the program and not only the loop.

One should indeed rather use last.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

  • Comment on Re: Re: Not Using So Many 'if' Statements

Replies are listed 'Best First'.
Re: Re: Re: Not Using So Many 'if' Statements
by insensate (Hermit) on Jan 09, 2003 at 20:40 UTC
    Right... last will break me out of my loop... but why not just exit as soon as I've accomplished the purpose of the script instead of adding an extra command?

    Update: Here's what I mean:
    Adding the last statement would require an additional conditional:
    my $success; for(@host){ $stout = run($_); unless($stout == 256) { $success++; last; } print "$_ not responding, trying next host\n"; } print "all hosts not responding" unless $success;

      Indeed, no reason why you should not use exit to kill the program if you're done. I was just pointing to the side-effects of exit: you may get more more than you bargained for.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law