Language DOS Batch
Date: | 04/20/05 |
Author: | Donavan Hoepcke |
URL: | n/a |
Comments: | 11 |
Info: | n/a |
Score: | (3.46 in 24 votes) |
@echo off REM 99 Bottles of Beer in DOS Batch REM First version by Gert-jan Los (los@lsdb.bwl.uni-mannheim.de) REM The file with batch program must be named as "beer.bat" REM Noted by Vladimir Vojacek (vojacek@seznam.cz), 2003-07-03 REM Last modified by Cory Boehne, 2004-01-01 if "%1"=="" goto outer if "%1"=="body" goto body :inner for %%a in ( 9 8 7 6 5 4 3 2 1 0 ) do call beer body %2 %%a goto end :outer for %%a in ( 9 8 7 6 5 4 3 2 1 0 ) do call beer inner %%a goto end :body set num=%2%3 set bottle=bottles if "%num%"=="99" set number=ninety-nine if "%num%"=="19" set number=nineteen if "%num%"=="09" set number=nine if "%num%"=="99" goto skipfirst if "%2"=="0" set num=%3 if "%num%"=="1" set bottle=bottle if "%num%"=="0" goto last echo %number% %bottle% of beer on the wall echo. :skipfirst echo %number% %bottle% of beer on the wall echo %number% %bottle% of beer if not "%num%"=="1" echo take one down and pass it around if "%num%"=="1" echo take it down and pass it around :last if "%num%"=="0" echo no more bottles of beer on the wall if "%num%"=="0" goto end if "%2"=="9" set numberi=ninety if "%2"=="8" set numberi=eighty if "%2"=="7" set numberi=seventy if "%2"=="6" set numberi=sixty if "%2"=="5" set numberi=fifty if "%2"=="4" set numberi=fourty if "%2"=="3" set numberi=thirty if "%2"=="2" set numberi=twenty if "%2"=="1" set numberi= if "%2"=="0" set numberi= if not "%2"=="1" goto secondnum if "%3%"=="9" set numberi=eighteen if "%3%"=="8" set numberi=seventeen if "%3%"=="7" set numberi=sixteen if "%3%"=="6" set numberi=fifteen if "%3%"=="5" set numberi=fourteen if "%3%"=="4" set numberi=thirteen if "%3%"=="3" set numberi=twelve if "%3%"=="2" set numberi=eleven if "%3%"=="1" set numberi=ten set numbe= goto numcat :secondnum if "%3"=="0" set numbe=nine if "%3"=="9" set numbe=eight if "%3"=="8" set numbe=seven if "%3"=="7" set numbe=six if "%3"=="6" set numbe=five if "%3"=="5" set numbe=four if "%3"=="4" set numbe=three if "%3"=="3" set numbe=two if "%3"=="2" goto lastone if "%3"=="1" set numbe= if not "%3"=="0" goto numcat if "%2"=="9" set numberi=eighty if "%2"=="8" set numberi=seventy if "%2"=="7" set numberi=sixty if "%2"=="6" set numberi=fifty if "%2"=="5" set numberi=fourty if "%2"=="4" set numberi=thirty if "%2"=="3" set numberi=twenty if "%2"=="2" set numberi= if "%2"=="1" set numberi= goto numcat :lastone if not "%2"=="0" set numbe=one if "%2"=="0" set numbe=one more :numcat if "%2"=="0" goto skipdash if "%2"=="1" goto skipdash if "%3"=="0" set numberi=%numberi%- if "%3"=="9" set numberi=%numberi%- if "%3"=="8" set numberi=%numberi%- if "%3"=="7" set numberi=%numberi%- if "%3"=="6" set numberi=%numberi%- if "%3"=="5" set numberi=%numberi%- if "%3"=="4" set numberi=%numberi%- if "%3"=="3" set numberi=%numberi%- if "%3"=="2" set numberi=%numberi%- :skipdash set number=%numberi%%numbe% :end
Download Source | Write Comment
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!
Comments
mackenga said on 07/14/05 19:10:00
Ye gods, this is almost as long as the Intercal version.
nik said on 12/13/05 20:59:30
use "call %0 body %2 %%a" instead of "call beer body %2 %%a" to make it independent of the file name.
Donavan Hoepcke said on 01/10/06 19:55:06
Ummm . . . this is cool except that I didn't write it. I think this must have been transposed when the site was redone. On the other hand, I _did_ contribute the Doc1 PCE listed directly above it.
Cory Boehne said on 02/07/06 00:46:44
Yeah, I did write it
It was really fun playing with a .bat file to this extent, hopefully they'll put this back into my name, but it's not critical....
Cheers all,
Cory Boehne
raivier said on 06/29/06 23:02:54
Lookig for codes and commands for DOS, email me where
Sivert Ellingsen said on 10/04/06 12:53:14
Here's a somewhat shorter version (I only know this works on XP).
@echo off
set /a bottles=99
set bottles2=bottles
:loop
echo %bottles% %bottles2% of beer on the wall, %bottles% %bottles2% of beer.
set /a bottles=%bottles% - 1
if %bottles%==1 set bottles2=bottle
if not %bottles%==1 set bottles2=bottles
if not %bottles% lss 1 echo Take one down and pass it around, %bottles% %bottles2% of beer on the wall.
if %bottles% lss 1 echo Take one down and pass it around, no more bottles of beer on the wall.
echo.
if not %bottles% lss 1 goto loop
echo No more bottles of beer on the wall, no more bottles of beer.
echo Go to the store and buy some more, 99 bottles of beer on the wall.
echo.
pause
Sivert Ellingsen said on 10/29/06 18:26:58
Shorter (and, IMHO, easier to read) still:
@echo off
for /l %%r in (99,-1,2) do (
if not %%r==99 echo %%r bottles of beer on the wall
if not %%r==99 echo.
echo %%r bottles of beer on the wall, %%r bottles of beer
echo You take one down, you pass it around )
echo.
echo No more bottles of beer on the wall
echo No more bottles of beer
echo Go to the store and buy some more
echo 99 bottles of beer on the wall
echo.
pause
Francis said on 02/15/07 19:48:28
That last (shortest) version doesn't work right.
3 bottles of beer on the wall, 3 bottles of beer
You take one down, you pass it around
2 bottles of beer on the wall
Above is the start of the output, which looks fine as far back as I can see. Below is where the ending is messed up:
2 bottles of beer on the wall, 2 bottles of beer
You take one down, you pass it around
No more bottles of beer on the wall
No more bottles of beer
Go to the store and buy some more
99 bottles of beer on the wall
Press any key to continue . . .
srm said on 03/27/07 16:53:42
yeah, here's the patch :D
@echo off
-for /l %%r in (99,-1,2) do (
+for /l %%r in (99,-1,1) do (
;P
said on 05/10/07 19:27:43
I don't like the New style CMD.Exe commands suggested here. They are not MS-DOS, they are windows one.
Using Set /A or For /L is not so funny; the funniest thing is using a counter in a language without counters, like COMMAND.COM (not CMD.EXE) batch language. A short counter would have been possible in old dos using command.com replacements, but the funny thing is using string-like counters, like that FOR %%A in (0,1,2,3,4,5 .. ) do CALL %0 %%A,
MS-DOS 3.30 user manual prevented against for .. do nesting; my first test about the real availability of for..do nesting was a counter very similar to this one, with 4 levels of nesting (0000 to 9999).
dani said on 09/06/07 19:30:23
i pefere the shortist versen