Loops/While: Difference between revisions

→‎{{header|Ruby}}: begin-end-while is actually do-while loop
(Added Perl 6 and slightly edited Perl 5.)
(→‎{{header|Ruby}}: begin-end-while is actually do-while loop)
Line 502:
i /= 2
end</lang>
Ruby also has a "while" statement modifier:
<lang ruby>i = 1024
begin puts i; i /= 2; end while i > 0</lang>
The above can be written in one statement (using the return value of the Kernel#puts method: nil is false), but the readability suffers:
<lang ruby>i = 1024
Anonymous user