Loops and the While Statement
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;