课程: Complete Guide to C Programming Foundations

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Nesting loops

Nesting loops

- [Instructor] There's really nothing a for loop can do that a while loop cannot do. Though there's one thing you can do better with a for loop than a while loop, and that's nesting loops. A nested loop is one loop inside another, as this exercise file demonstrates. The outer loop uses variable row to count from one through 10. The inner loop uses variable column to count from value letters A through J. The printf statement outputs the current row and column values plus three spaces. And a putchar statement at line 14 adds a new line character to the end of each line output, making a nice, neat grid. Run to see the nice, neat grid. And there it is. Nested loops are most frequently related to information shown in grids. The outer loop repeats only after the inner loop is done repeating a given number of times. This exercise file shows the while loop version of the same code, because the while loop statement contains only the looping condition for additional statements that are required…

内容