While loop, foreach loop, and block and redo : Redo « Statement « Perl






While loop, foreach loop, and block and redo


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

my $n = 0;

print "With a while loop:\n";
while (++$n < 4) { 
   print "Hello $n \n"; 
}

print "With a foreach loop:\n";
foreach my $n (1..3) { 
  print "Hello $n \n"; 
}

print "With a bare block and redo: \n";
$n = 1; { 
   print "Hello $n \n";
   last if (++$n > 3); 
   redo; 
}

 








Related examples in the same category

1.Using the redo statement in a while structure.
2.redo statement
3.A word-counting program that uses the redo statement.
4.Using a label without a loop and the redo statement