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.
Setting up a while loop - C Tutorial
From the course: Complete Guide to C Programming Foundations
Setting up a while loop
- [Instructor] The C language keyword while constructs a loop of one or more repeating statements. The keyword is followed by parentheses containing the loop's expression. While this expression evaluates true, the statements repeat. Like other C constructions when more than a single statement is repeated, they all must be enclosed in braces. Unlike a for loop, the while loop statement contains only the while true looping condition, which must remain true for the statements to repeat. Therefore, the loop's condition must be initialized before the loop starts as a separate statement. Further, the loop's statements must contain its exit strategy, something that alters the condition the while statement evaluates and eventually terminates the loop. The while loop in this exercise file repeats 10 times. Variable a is initialized to zero at line seven. This is the setup. The loop's statements repeat as long as the value of variable a is less than 10. At line 11, variable a is modified, which…
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
-
-
-
-
-
-
-
-