Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
No, if every element of @x is less than the first element of @y, then all of @x first gets nibbled element by element because of the first statement within the loop, then all of @y gets nibbled element by element because of the second statement within the loop, and then we drop out of the loop.
Perhaps you're arguing that I can optimize that to "and". Probably true. But it doesn't break even when it's an "or", unless I'm missing something. I constructed this loop by thinking about loop invariants, a very valuable tool. In this case, we know that no pair of equal numbers can ever get shifted off the lists, and yet we are shifting while we are looping, so we're always moving closer to either an equal pair, or two empty lists. -- Randal L. Schwartz, Perl hacker
In reply to •Re: Re: •Re: Pair of items
by merlyn
|
|