use strict;
use warnings;
my @array = (1 .. 4);
while (@array) {
my $first = shift @array;
print "[$first]";
push @array, $first / 2 if (!($first % 2));
}
####
[1][2][3][4][1][2][1]
####
use strict;
use warnings;
my @array = (1 .. 4);
for my $element (@array) {
print "[$element]";
push @array, $element / 2 if (!($element % 2));
}