The instructor presents both solutions to the challenge, one using a for loop and the other using while. The positives and negatives of each approach are reviewed.
(upbeat music) … - [Instructor] To make the loop work in your solution, … you need a second variable. … I've added variable B … to the declaration of variable A here at line five. … The for loop appears at line 10. … Variable B is initialized to zero. … The loop repeats while variable B … is less than the value of variable A, … which is what the user input. … And each time the loop repeats, variable B is incremented. … The single repeating statement is putchar here at line 11. … I added a second putchar statement here at line 12 … to terminate the new line, which helps clean up output. … Build and run, … and I'll type 50, and you see 50 hyphens. … I know it's 50 hyphens, I'm not going to count them. … Here's my while loop variation for the solution. … It also requires a second variable B, … which is initialized here at line 10. … And you don't have to call it variable B, … but you do need a second variable. … The while loop repeats, as long as the value of variable B … is less than the value of variable A. …
- 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.