Bootstrap FreeKB - Perl (Scripting) - while loop
Perl (Scripting) - while loop

Updated:   |  Perl (Scripting) articles

while loop can be used to do something until a certain condition is true. For example.

#!/usr/bin/perl
use strict;
use warnings;

my $integer = 0;

while ($integer < 5) {
  print "$integer is less than 5 \n";
  ++$integer;
}

 

Or this.

#!/usr/bin/perl
use strict;
use warnings;

my $integer = 0;

do {
  print "$integer is less than 5 \n";
  ++$integer;
} while ($integer < 5);

 

. . . will produce the following output.

0 is less than 5 
1 is less than 5 
2 is less than 5 
3 is less than 5 
4 is less than 5

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2ec840 in the box below so that we can be sure you are a human.