in reply to Re: Doing "it" only once
in thread Doing "it" only once
Perl6 will have a FIRST block, meaning the block will be executed only once, and to be specific, the first time the surrounding block was entered. If you write this:
and perl can determine there are no side-effects in the conditional, perl could be made to optimize away the conditional once it was true once.while (...) { if (/foo/) { FIRST {...; next} } ... }
Having said that, the original problem isn't clearly defined. Suppose there would be this 'once-only if', what should the following print:
Should it print 'foo' once, or twice? That is, is the "once-only" a property of the enclosing loop, to be reset when that loop is reentered, or a property of the condition itself, meaning that after it became true once, it will never be true in the life-time of the program?my @list = qw /foo bar foo/; for my $x (1, 2) { for (@list) { if (/foo/) { # Assume a 'once-only if' print "foo"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Doing "it" only once
by QM (Parson) on Sep 22, 2005 at 17:51 UTC | |
by Anonymous Monk on Sep 23, 2005 at 09:06 UTC | |
by QM (Parson) on Sep 23, 2005 at 12:07 UTC |