From the course: C Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Setting up a while loop - C Tutorial
From the course: C Essential Training
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 looping expression, while this expression evaluates true, the statements repeat. And similar to other C constructions, when more than a single statement is repeated, they 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. 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. The while loop in this exercise file, repeats 10 times. Variable a is initialized to zero at line seven. The loop's statements repeat as long as the value of variable a is less than 10. Importantly, at line 11…
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
-
Exploring the possibilities2m 34s
-
Using the ternary operator3m 1s
-
Working with the switch-case structure4m 9s
-
Challenge: Select an item29s
-
Solution: Select an item57s
-
Creating a for loop3m 58s
-
Setting up a while loop3m 6s
-
Challenge: Repeat some text48s
-
Solution: Repeat some text1m 40s
-
Nesting loops1m 55s
-
Breaking out of a loop3m 28s
-
Avoiding the goto keyword1m 56s
-
Challenge: Work the grid2m 21s
-
Solution: Work the grid2m 8s
-
-
-