Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Cobra

Date:07/11/10
Author:Tim Locke
URL:n/a
Comments:0
Info:http://cobra-language.com/
Score: (3.97 in 123 votes)
# 99 Bottles of Beer

class BottlesOfBeerSong

    def pluralize(count as int) as String
        if count == 1
            return ""
        else
            return "s"

    def beer(bottles as int) as String
        if bottles == 0
            return "No more"
        else
            if bottles == -1
                return "99"
            else
                return bottles.toString

    def bottlesOfBeer(bottles as int) as String
        return .beer(bottles) + " bottle" + .pluralize(bottles) + " of beer"

    def onTheWall(bottles as int) as String
        return .bottlesOfBeer(bottles) + " on the wall"

    def bottleFall(bottles as int) as String
        if bottles == 0
            return "Go to the store and buy some more, "
        else
            return "Take one down and pass it around, "

    def main
        for bottle as int in 99 : -1 : -1
            print .onTheWall(bottle) + ", " + .bottlesOfBeer(bottle) + ","
            print .bottleFall(bottle) + .onTheWall(bottle-1) + "."
            print

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: