Loops/While: Difference between revisions

→‎{{header|Perl 6}}: simplification
(added Applesoft BASIC implementation)
(→‎{{header|Perl 6}}: simplification)
Line 785:
=={{header|Perl 6}}==
 
Here is a straightforward translation of the task description:
Note that <tt>+></tt> is the Perl 6 right bit-shift operator, it is equivalent to dividing by two. The <tt>+</tt> indicates that it is a numeric operation, and the <tt>></tt> indicates that it is the right bit-shift operation since the tag is pointing to the right.
<lang perl6>saymy $n = 1024; +>while $_n for> 0..10 { say $n; $n div= 2 }</lang>
 
The same thing with a C-style loop and a bitwise shift operator:
<lang perl6>my $n = 1024*2;
<lang perl6>loop (my $n = 1024; $n > 0; $n +>= 1) { say $n }</lang>
 
say $n while ($n +>= 1) != 0;</lang>
 
Here is a solution without the restraints:
 
<lang perl6>say 1024 +> $_ for 0..10;</lang>
 
And here's how you'd <em>really</em> write it, using a sequence operator that intuits the division for you:
 
<lang perl6>.say for 1024, 512, 256 ... 1 { .say }</lang>
 
=={{header|PHP}}==
1,934

edits