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
- 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Making a decision3m 37s
-
(Locked)
Exploring the possibilities2m 34s
-
(Locked)
Using the ternary operator3m 1s
-
Working with the switch-case structure4m 9s
-
(Locked)
Challenge: Select an item29s
-
(Locked)
Solution: Select an item57s
-
(Locked)
Creating a for loop3m 58s
-
(Locked)
Setting up a while loop3m 6s
-
(Locked)
Challenge: Repeat some text48s
-
(Locked)
Solution: Repeat some text1m 40s
-
(Locked)
Nesting loops1m 55s
-
(Locked)
Breaking out of a loop3m 28s
-
(Locked)
Avoiding the goto keyword1m 56s
-
(Locked)
Challenge: Work the grid2m 21s
-
(Locked)
Solution: Work the grid2m 8s
-
-
-