www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [your code here] 99 bottles of beer

reply Pseudo Nym <pseudonym example.thisisnotatld> writes:
import std.stdio;
import std.conv;

void main() {
	const string drink = "beer";

	int bottles = 99;
	while (bottles > 0) {
		string amt = to!string(bottles);
		writeln(amt ~ " bottles of " ~ drink ~ " on the wall, " ~ amt ~ 
" bottles of " ~ drink ~ ". Take one down, pass it around, " ~ 
to!string(--bottles) ~ " bottles of " ~ drink ~ " on the wall.");
	}

}
Oct 13 2018
parent reply SrMordred <patric.dexheimer gmail.com> writes:
import std.format;
template Bootle(alias Beer = 0)
{
     static if(Beer < 99)
         enum Bootle = Bootle!(Beer + 1);
     else
         enum Bootle = Beer;
     pragma(msg,
		format!"%d bottles of beer on the wall, %d bottles of beer. 
Take one down, pass it around, %d bottles of beer on the wall."
		(Beer ,Beer, Beer-1)
	);

}
enum BootleBeer = Bootle!1;
void main(){}

:P
Oct 15 2018
parent David Bennett <davidbennett bravevision.com> writes:
--- ct_beer.d

static foreach_reverse(beer; 1..100)
{
	pragma(msg, beer, " bottles of beer on the wall, ", beer, " 
bottles of beer. Take one down, pass it around, ", beer-1, " 
bottles of beer on the wall.");
}

void main(){}

---
Oct 15 2018