From the course: C Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Nesting loops

Nesting loops - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Nesting loops

- There's really nothing a for loop can do that a while loop cannot. Though there's one thing you can do better with a for loop than with a while loop, and that's nesting loops. A nested loop is one loop inside of another. In this exercise file, the outer loop uses variable row to count from one to 10. The inner loop uses variable column to count from letter "A" to letter "J". The printf statement outputs the values row and column in a format. The putchar statement here at line 14 adds a new line character to the end of each line output making a nice, neat, grid. Build and run. Nested loops are most frequently related to information shown in a grid. And you can triple nest loops as well. The outer loop repeats only after the inner loop is done repeating a number of times. This exercise file shows the while loop version of the same code. Because the while loop contains only the looping condition, four extra…

Contents