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

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