Unlike for and while loops, they test the loop condition at the head of the loop. In Perl, a 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 ensures that the loop is executed at least once.
The syntax format is as follows:
do{ statement(s);}while( condition );
Note that the conditional expression appears at the end of the loop, so the statement(s) in the loop will be executed at least once before the condition is tested.
If the condition is true, the control flow will jump back to the do above, and then re-execute the statement(s) in the loop. This process is repeated until the given condition becomes false.
Executing the above program, the output result is:
The value of a is: 10 The value of a is: 11 The value of a is: 12a The value of a is: 13a The value of a is: 14