See http://www.99-bottles-of-beer.net/
Simple version:
import System.Threading def getbottle(n as int): return "no more bottles of beer" if n==0 return "1 bottle of beer" if n==1 return "$n bottles of beer" b = getbottle(n = 5) while true: print "$b on the wall, $b," if n > 0: print "take one down, pass it around," else: print "go to the store, buy some more," n=100 b=getbottle(--n) print "$b on the wall." print Thread.Sleep(1000) |
OOP version:
import System.Threading class Bottle: [Property(Type)] static type = "beer" static start = 99 static count = start static Count: get: return count set: count = value start = value id as int private def constructor(n as int): id = n static def take() as Bottle: if count > 0: print "take one down, pass it around," return Bottle(--count) return null static def buy() as Bottle: count = start + 1 print "go to the store, buy some more," return Bottle(--count) static State as string: get: return Bottle.ToString() static def ToString(): s = "$count bottle" s += "s" if count != 1 s += " of $type" return s Bottle.Count = 5 while true: print "$(Bottle.State) on the wall, $(Bottle.State)," b = Bottle.take() or Bottle.buy() print Bottle.State, "on the wall!" print Thread.Sleep(1000) |