On Thu, Jul 19, 2001 at 07:30:10AM +0900, Dat Nguyen wrote:

# How to shorten the following experimental codes?

> bottle = ' bottles'
> 99.downto(1) { |i|
>     print "\n", i, bottle, ' of beer on the wall, ', i, bottle, ' of beer',
> ".\n"
>     print 'Take one down, pass it around,', "\n"
>     bottle = ' bottle' if i == 2
>     print i-1, bottle, ' of beer on the wall.', "\n" if i > 1
> }
> print 'No bottles of beer on the wall.', "\n\n"
> 
> # Thanks
> 
> # Dat

# ---

99.downto(1) { |i|
    s = (i != 1) ? "s" : "";

    print "#{i} bottle#{s} of beer on the wall.\n\n" if i < 99

    print "#{i} bottle#{s} of beer on the wall, #{i} bottle#{s} of beer.\n"
    print "Take one down, pass it around,\n"
}
print "No more bottles of beer on the wall.\n\n"

# ---

one less line, less quotes ( a matter of personal preference i suppose ), and handles bottle/bottles in a shorter way.

-- 

3rd Law of Computing:
        Anything that can go wr
fortune: Segmentation violation -- Core dumped