Perl: While Loop



Perl while loop is quite easy to understand:

 #!/usr/bin/local/perl
 $a = 'programmingbulls'; 
$count = 0; 
while ($count < 10)
{ 
print '$a \n'; 
$count++; 
} 

The above program would print programmingbulls 10 times.

Another useful example can be when asking for an input from user:

 #!/usr/bin/local/perl
 print "Enter Password ";	
 $a = <STDIN>;
 chop $a;
 while ($a ne 'programmingbulls'){
 print 'wrong input \n';
 $a =  chop $a; 
}

The code in curly block of code is executed till the input does not equal the text "programmingbulls".