Pathologically Eclectic Rubbish Lister | |
PerlMonks |
do while loopsby root (Monk) |
on Nov 05, 1999 at 04:49 UTC ( [id://950]=perltutorial: print w/replies, xml ) | Need Help?? |
while loops test the condition before every execution of the loop. Sometimes you want it to be tested after the loop.
This guarantees that the loop is run once before the condition is tested. $value=5 do{ print "$value\n"; $value=$value-1; } while($value>10); The above code prints out: 5 Then it tests $value which is now equal to 4 to see if it greater than 10. Since it is not the code within the loop is not run again Next find out about do until loops
Back to
Tutorials
|
|