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 - C Tutorial
From the course: Complete Guide to C Programming Foundations
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
-
-
-
-
-
-
Making a decision3m 25s
-
(Locked)
Exploring the possibilities2m 53s
-
(Locked)
Using the ternary operator3m
-
Working with the switch-case structure4m
-
(Locked)
Challenge: Select an item28s
-
(Locked)
Solution: Select an item1m 45s
-
Creating a for loop3m 36s
-
(Locked)
Setting up a while loop2m 58s
-
(Locked)
Challenge: Repeat some text51s
-
(Locked)
Solution: Repeat some text1m 51s
-
(Locked)
Nesting loops1m 59s
-
(Locked)
Breaking out of a loop3m 16s
-
(Locked)
Avoiding the goto keyword1m 33s
-
(Locked)
Chapter challenge: Interpreting commands2m 26s
-
(Locked)
Chapter solution: Interpreting commands3m 55s
-
-
-
-
-
-
-
-