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 Openedge (Progress 4GL)

Date:01/14/08
Author:Elwin van der Meer
URL:http://www.star-lite.nl
Comments:1
Info:http://www.progress.com/
Score: (3.00 in 16 votes)
/*------------------------------------------------------------------------
    File        : 99bottles.p
    Purpose     : http://www.99-bottles-of-beer.net/
    Description : 99 bottles of beer
    Author(s)   : Elwin van der Meer
                : elwin@star-lite.nl
                : http://www.star-lite.nl
    Created     : Fri Jan 11 13:31:49 CET 2008
  ----------------------------------------------------------------------*/
DEFINE VARIABLE amountofbottles AS INTEGER NO-UNDO INITIAL 99.
&GLOBAL-DEFINE bbm bottles of beer
&GLOBAL-DEFINE bbs bottle of beer
&GLOBAL-DEFINE otw on the wall
&GLOBAL-DEFINE tow Take one down and pass it around,
&GLOBAL-DEFINE gts Go to the store and buy some more,
FUNCTION drinkBottle RETURNS INTEGER PRIVATE (INPUT bc AS INTEGER) FORWARD.

OUTPUT TO OUTPUT.txt.
drinkBottle(amountofbottles).
OUTPUT CLOSE.

FUNCTION drinkBottle RETURNS INTEGER.
    IF bc >= 0 THEN DO:
        CASE bc:
        WHEN 2 THEN
            PUT UNFORMATTED bc " {&bbm} {&otw}, " bc " {&bbm}" SKIP 
                            "{&tow} " bc - 1 " {&bbs} {&otw}" SKIP.
        WHEN 1 THEN
            PUT UNFORMATTED bc " {&bbs} {&otw}, " bc " {&bbs}" SKIP 
                            "{&tow} no more {&bbm} {&otw}" SKIP.
        WHEN 0 THEN
            PUT UNFORMATTED "no more" " {&bbm} {&otw}, no more {&bbm}" SKIP 
                            "{&gts} " amountofbottles " {&bbm} {&otw}" SKIP.
        OTHERWISE
            PUT UNFORMATTED bc " {&bbm} {&otw}, " bc " {&bbm}" SKIP 
                            "{&tow} " bc - 1 " {&bbm} {&otw}" SKIP.
        END CASE.        
        drinkBottle(bc - 1).
        RETURN bc.
    END.
    RETURN 0. 
END FUNCTION.

Download Source | Write Comment

Alternative Versions

Comments

>>  AxelF said on 09/11/09 11:33:05

AxelF Works like a charm :)

Though I'd prefer to call the function 99 times in stead of once since that defeats the purpose of using a function in my opinion.

ABL ftw!

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: