lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


--- Philippe Lhoste <PhiLho@MailAndNews.com> wrote:
> Of course, I checked to see if Lua was showcased. Not! So I choose to make my 
> first Lua program with this exercice. Here is my work:
> 
> function PrintBottleNumber(n)
>  local bs
>  if n == 0 then
>     bs = "No more bottles"
>  elseif n == 1 then
>     bs = "One bottle"
>  else
>     bs = n .. " bottles"
>  end
>  return bs .. " of beer"
> end
> 
> for bn = 99, 1, -1 do
>  write(PrintBottleNumber(bn), " on the wall, \n")
>  write(PrintBottleNumber(bn), "\n")
>  write("Take one down and pass it around,\n")
>  write(PrintBottleNumber(bn-1), " on the wall, \n\n")
> end
> write("No more bottles of beer on the wall,\nNo more bottles of beer\n")
> write("Go to the store, buy some more!\n")

Bizarre... I just posted a Lua entry to that site a few weeks ago:

   function bottle(n)
      if     n==0 then return 'no more bottles'
      elseif n==1 then return '1 bottle'
      else             return n..' bottles'
      end
   end

   n=99
   while (n > 0)
      print (bottle(n)..' of beer on the wall,')
      print (bottle(n)..' of beer.\nTake one down,\npass it around,')
      n = n - 1
      print (bottle(n)..' of beer on the wall.\n')
   end

Pretty dang close (though yours is a bit better).

Cheers,
Eric


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/