Perl do... While loop
Unlike for and while loops, they test cycle conditions at the loop head. I n the Perl language, do... The while loop is a condition that checks for it at the end of the loop.
do... T he while loop is similar to the while loop, but do... The while loop ensures that the loop is executed at least once.
Grammar
The syntax format looks like this:
do { statement(s); }while( condition );
Note that the conditional expression appears at the end of the loop, so statement(s) in the loop is executed at least once before the condition is tested.
If the condition is true, the control flow jumps back to the do above and then re-executes the statement (s) in the loop. This process is repeated until the given condition becomes false.
Flow chart
Instance
#!/usr/bin/perl $a = 10; # 执行 do...while 循环 do{ printf "a 的值为: $a\n"; $a = $a + 1; }while( $a < 15 );
The above procedure is performed and the output is:
a 的值为: 10 a 的值为: 11 a 的值为: 12 a 的值为: 13 a 的值为: 14