4-3 Subpage 1: The Algorithmic Pattern

This subpage is dedicated to the algorithmic pattern, where the code is as much a work of art as it is a functional program.

Here is a simple example of a recursive function that prints numbers from 1 to n:

function printNumbers(n) {
		if (n === 0) {
			return;
		}
		printNumbers(n-1);
		console.log(n);
	}

And here is an example of an infinite loop that prints numbers from n to infinity:

while (n > 0) {
		console.log(n);
		n--;
	}

These patterns can be used to create all sorts of interesting and confusing outputs, like: