Syntax :
It can be used as do-until loop or simply until loop
1)
do
{
STATEMENTS
}until (CONDITION);
2)
until(CONDITION)
{
STATEMENTS;
}
Example:
1)
Content of the perl file:
$num=20;
do
{
print "the num is $num"."\n";
$num++;
}
until($num >30 )
OUTPUT:
G:\perl_programs>perl perl_until.pl
the num is 20
the num is 21
the num is 22
the num is 23
the num is 24
the num is 25
the num is 26
the num is 27
the num is 28
the num is 29
the num is 30
G:\perl_programs>
Content of the perl file:
$num=20;
until( $num > 30) {
OUTPUT:
G:\perl_programs>perl perl_until.pl
the num is 20
the num is 21
the num is 22
the num is 23
the num is 24
the num is 25
the num is 26
the num is 27
the num is 28
the num is 29
the num is 30
G:\perl_programs>
The main differece between the two in the case of do loop statement will be executed atleast one irrespective of the condition is true or false.
No comments:
Post a Comment