13.4 Multiple Layers of Nesting

There’s no limit as to how deeply we can nest our programming constructs. For example, we can extend our alphabet-printing program from earlier to print as many letter combinations as we like just by adding extra loops. This version prints out all possible quadruplets of letters from the alphabet:

The above program might not run because it takes so much computing power. Here's a video of it:

Sometimes, a single Boolean expression can replace multiple layers of nesting. The following two programs are an example of this. They have the same behaviour, but the program 13.3 uses multiple nested if-statements, while program 13.4 uses a single if-statement with the conditions from 13.3’s nested-if statements expressed as a single Boolean expression.

In this case, neither of these programs are necessarily more “correct” than the other; it’s a matter of which one is easier for a human reader to understand. For now, the point is to show a programming language is like a natural language, in there are often many ways to express the same idea.