How to Create a Do While Loop in Perl
A do while loop is almost exactly like a while loop, with one major difference: the code in the loop body is executed before the while condition is evaluated. This means that even if the while condition is false, the code will execute once, whereas it would never execute in the case of a while loop.
Instructions
-
-
1
Code the
doloop by specifying thedokeyword, followed by curly brackets enclosing the statments comprising the loop body, and ending with thewhilekeyword and termination condition.
do {
# Your code
} while (expression);
-
1
Tips & Warnings
Avoid infinite loops by ensuring that the while condition will eventually become true, or the loop has another way to exist, such as via a
laststatement.