Factorial in D

Example for versions D1, D2, gdc 0.24

This example uses iterative factorial definition. Note the usage of foreach loop.

module factorial;

import std.stdio;

ulong iterative(ulong x) {
	ulong result = 1;
	foreach (ulong count; 1..x+1)
		result *= count;
	return result;
}

int main() {
	foreach (int i; 0..17)
		writefln("%s! = %s", i, iterative(i));
	return 0;
}