Variables and Assignment Statements
16. A Sequence that Counts
Answer:
The program will print out:
value is: 5
value is: 15
A Sequence that Counts
Look at this program fragment. Click inside the program to see how it works.
|
Here is how the program works:
- Statement 1 puts 0 into
count
. - Statement 2 writes out the 0 in
count
. - Statement 3 first gets the 0 from
count
, adds 1 to it, and puts the result back incount
. - Statement 4 writes out the 1 that is now in
count
.
When the fragment runs, it writes:
0 1
Question 17:
Think of a way to write 0, 1, and 2.