Completion requirements
Read this chapter, which explains while loops. This is in contrast to how a do-while loop works, which we will discuss later. In a do-while loop, the body of the loop is executed at least one time, whereas in a while loop, the loop may never execute if the loop condition is false.
3. Incrementing count
Answer:
count = count + 1;
It increases count
by one.
Incrementing count
count
If the answer is not clear, remember the two steps of an assignment statement:
- first evaluate the expression on the right of the equal sign,
- second put the value in whatever variables on the left.
Say that count
is 2. When the above statement executes, first the expression count + 1
is evaluated, resulting in 3. Second the 3 is put in count
.
Question 3:
What does this statement do:
count = count + 2;