YouTip LogoYouTip

Perl Do While Loop

# Perl do...while Loop [![Image 4: Perl Loops](#) Perl Loops](#) Unlike **for** and **while** loops, which test the loop condition at the beginning of the loop, in Perl, the **do...while** loop checks its condition at the end of the loop. The **do...while** loop is similar to the while loop, but the do...while loop will ensure that the loop body is executed at least once. ### Syntax The syntax format is as follows: do{ statement(s);}while( condition ); Please note that the condition expression appears at the end of the loop, so the statement(s) inside the loop will be executed at least once before the condition is tested. If the condition is true, the control flow jumps back to the do above and re-executes the statement(s) in the loop. This process repeats until the given condition becomes false. ### Flowchart ![Image 5: do...while Loop in Perl](#) ## Example #!/usr/bin/perl$a = 10; # Execute do...while loop do{printf"The value of a is: $an"; $a = $a + 1; }while($a<15); Executing the above program yields the following output: The value of a is: 10 The value of a is: 11 The value of a is: 12 The value of a is: 13 The value of a is: 14 [![Image 6: Perl Loops](#) Perl Loops](#)
← Perl Next StatementPerl For Loop β†’