[DFW.pm] Homework for the list, and for Oct 08 meeting
Patrick R. Michaud
pmichaud at pobox.com
Thu Sep 11 11:32:35 PDT 2014
Perl 6 solution #1, the straightforward one:
for 1..100 {
when $_ %% (3 & 5) { say "FizzBuzz" }
when $_ %% 5 { say "Buzz" }
when $_ %% 3 { say "Fizz" }
say $_;
}
Some explanation:
- The Perl 6 "%%" operator returns true if the left argument is evenly
divisible by the right argument.
- The "when" keyword is Perl 6's version of a "switch/case" statement;
when the test is true, the block following it is executed and control
skips to the end of the enclosing block.
- The expression "$_ %% (3 & 5)" is true if $_ is evenly divisible
by both 3 and 5. (The "&" operator in Perl 6 creates a junction
of values, the numeric bitwise-and operator in Perl 6 is "+&".)
Pm
More information about the Dfw-pm
mailing list