Until loop behaves just opposite to the while loop in perl, while loop continues execution as long as the condition is true. In until loop, the loop executes as long as the condition is false.
Syntax of until loop:
until(condition) { statement(s); }
Flow of Execution of the until Loop
The condition is evaluated first, if it returns false, the statements inside loop gets executed. After execution the condition is re-evaluated. This goes on until the condition returns true. Once the condition returns true, the control gets transferred to the next statement after until loop.
Example
#!/usr/local/bin/perl $num = 10; until( $num >15 ){ printf "$num\n"; $num++; }
Output:
10 11 12 13 14 15
Leave a Reply