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.
Creating a for loop
- [Instructor] Along with decision making, another way to control program flow is one of the basic concepts of computer programming, the loop. A loop is one or more statements that repeat. The loop's condition determines how many times the statements repeat. Three C language keywords deal with loops, for, while and do. Loops feature three parts, a starting condition or initialization, an expression that must remain true for the statements to repeat and an exit condition to terminate the loop. In a for loop, all three conditions are expressed in the keywords parentheses as shown in this exercise file. The starting condition or a loop initialization appears first. Variable a is initialized to zero. A semi-colon separates the expressions in a for statement. Next comes the condition. The loop repeats as long as the value of variable a is less than 10, then comes another semi-colon, and then finally the expression…
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
-
-
-