10.2. The until Control StructureSometimes you'll want to reverse the condition of a while loop. To do that, just use until: until ($j > $i) { $j *= 2; } This loop runs until the conditional expression returns true. But it's really just a while loop in disguise, except that this one repeats as long as the conditional is false, rather than true. The conditional expression is evaluated before the first iteration, so this is still a zero-or-more-times loop, just like the while loop.[215]
As with if and unless, you could rewrite any until loop to become a while loop by negating the condition. But generally, you'll find it simple and natural to use until from time to time. Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|