Pure Programmer

# Iteration

Iteration1.pl
```#!/usr/bin/env perl
use utf8;
use Utils;
use strict;
use warnings;

MAIN:
{
my \$max = 5;
if (scalar(@ARGV) == 1) {
\$max = Utils::stoiWithDefault(\$ARGV[0], 5);
}
for (my \$i = 0; \$i < \$max; ++\$i) {
print "Hello, world!\n";
}
}

```
Output
\$ perl Iteration1.pl 5 Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
Iteration2.pl
```#!/usr/bin/env perl
use utf8;
use strict;
use warnings;

MAIN:
{
for (my \$i = 10; \$i >= 1; --\$i) {
print \$i, "\n";
}
print "Blastoff!\n";
}

```
Output
\$ perl Iteration2.pl 10 9 8 7 6 5 4 3 2 1 Blastoff!
Iteration3.pl
```#!/usr/bin/env perl
use utf8;
use strict;
use warnings;

MAIN:
{
print "Even numbers up to 100...\n";
for (my \$i = 2; \$i <= 100; \$i += 2) {
print \$i, "\n";
}
}

```
Output
\$ perl Iteration3.pl Even numbers up to 100... 2 4 6 8 10 12 14 16 18 ... 82 84 86 88 90 92 94 96 98 100
Iteration4.pl
```#!/usr/bin/env perl
use utf8;
use strict;
use warnings;

MAIN:
{
print "Floating point numbers\n";
for (my \$d = 1.0; \$d < 2.01; \$d += 0.1) {
print \$d, "\n";
}
}

```
Output
\$ perl Iteration4.pl Floating point numbers 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
Iteration5.pl
```#!/usr/bin/env perl
use utf8;
use strict;
use warnings;

MAIN:
{
print "Powers of 2 up to 256!\n";
for (my \$i = 1; \$i <= 256; \$i *= 2) {
print \$i, "\n";
}
}

```
Output
\$ perl Iteration5.pl Powers of 2 up to 256! 1 2 4 8 16 32 64 128 256
Iteration6.pl
```#!/usr/bin/env perl
use utf8;
use strict;
use warnings;

MAIN:
{
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
binmode(STDIN, ":utf8");
my \$s = "Hello, world! 🥰🇺🇸";
foreach my \$c (split('', \$s)) {
print \$c, "\n";
}
}

```
Output
\$ perl Iteration6.pl H e l l o , w o r l d ! 🥰 🇺 🇸

perl

## Questions

• {{Who's on first?}}
• {{Who's on second?}}
• {{Who's on third?}}

## Projects

More ★'s indicate higher difficulty level.

## References

• [[Perl Language Reference]]
• [[Comprehensive Perl Archive Network (CPAN)]]
• [[Beginning Perl]], Simon Cozens
• [[Perl Monks Tutorials]]