A nested loop is one loop inside another—an inner loop and an outer loop—and they're ideal for working with data presented in a grid or matrix. The best approach to writing a nested loop is to use the for keyword, which has a more detailed looping statement, but less material to keep track of than when using a while loop.
- 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 statements are required … to make nested loops work with while. …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.