Example 8-5. examples/p526/control_structures.p6
#!/usr/bin/perl6
# Perl5: if
# No need to for () around the condition
my $x = 23;
if $x < 42 {
}
# Perl5: foreach (for)
my @names = <Larry Guido Matz>;
for @name -> $person {
say $person;
}
# Perl5: for (foreach)
loop (my $i=1; $i < 10; $i++) {
say $i;
}
# infinite loop:
loop {
# well, almost infinite :-)
last;
}
# Perl5: while
my $x = 1;
while $i < 10 {
say $i;
}
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Hashes | Up | Functions |