Language PL/I
Date: | 04/20/05 |
Author: | Anonymous |
URL: | n/a |
Comments: | 4 |
Info: | n/a |
Score: | ![]() |
/* And here is the PL/I version: */ BOTTLES: PROC OPTIONS(MAIN); DCL NUM_BOT FIXED DEC(3); DCL PHRASE1 CHAR(100) VAR; DCL PHRASE2 CHAR(100) VAR; DCL PHRASE3 CHAR(100) VAR; DO NUM_BOT = 100 TO 1 BY -1; PHRASE1 = NUM_BOT||' Bottles of Beer on the wall,'; PHRASE2 = NUM_BOT||' Bottles of Beer'; PHRASE3 = 'Take one down and pass it around'; DISPLAY(PHRASE1||PHRASE2); DISPLAY(PHRASE3); END; PHRASE1 = 'No more Bottles of Beer on the wall, '; PHRASE2 = 'No more Bottles of Beer'; PHRASE3 = 'Go to the store and buy some more'; DISPLAY(PHRASE1||PHRASE2); DISPLAY(PHRASE3); END BOTTLES;
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
PHRASE1 = "Bottles of beer"
PHRASE2 = " on the wall"
and save 15 bytes.
And why do so few of these examples properly deal with the case of "1 Bottle of beer", avoiding the plural?
What a fun site, though. I've been digging up old languages I'd forgotten about since college.
1. the DCL's for PHRASE1/2 etc can be made a STATIC structure of two fields (avoids dynamic allocation memory of VAR and allows first 2 characters to be replaced)
2. the DCL for PHRASE3 etc can be made STATIC
2. the DCL's for PHRASE1 etc can be initialized with model phrases 'xx bottles...'
(to avoid the 3 x full length assignments in the loop)
3. To avoid all arithmetic, an array of 100 char strings '99' through to 'No' can be declared and assigned to the beginning 2 bytes of each phrase.
4. Loop can be for 100 to zero to avoid last 3 assignments. Then, only the Display phrase3 is needed after the loop
QED
Well done- made me smile after building it on MVS38J on Hercules.