Nested Iteration Statements

The loop body of any iteration statement can consist of one or more statements. Because each iteration statement is a statement in itself, it can be nested inside the loop body of another iteration statement. An infinite number of iteration statements can be nested inside each other.

A nested loop consists of one loop (called an inner loop) residing inside another loop (called an outer loop).

Every time the outer loop executes its loop body once, the inner loop executes all of its loops. To illustrate this process, let's first have a look at an example containing only a single for loop and no nested loops yet. In a moment, we will expand this example with a nested for loop. Our first modest aim here is to construct ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.