From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Repeat some text

Solution: Repeat some text

(upbeat music) - [Instructor] To write my for loop solution, I'm using only one variable, variable A. True you could use two, but you really need only one. The for loop doesn't need to initialize variable A as its value is already set. So this part is blank. The loop repeats as long as the value of variable A is greater than zero, and then each time the loop repeats, one is subtracted from A, A is decremented. Within the loop the put care function outputs a single hyphen After the line is drawn, another put care statement outputs a new line, which helps clean up the output. And let's draw a line of 50 hyphens. There it is beautiful. For the while loop variation, the condition is the same as in the for loop. A is greater than zero. Again, A doesn't need to be initialized because the value of A is already set here in the scan F function. Braces are required because two statements are needed. The first outputs the hyphen, and a second statement to trigger the terminating condition…

Contents