Question 11
What is the output of the following code? [3 marks]
Solution
A variable x with value 10 is declared.
x |
x < 100? |
New x: x += x |
|---|---|---|
10 |
True |
10 + 10 = 20 |
20 |
True |
20 + 20 = 40 |
40 |
True |
40 + 40 = 80 |
80 |
True |
80 + 80 = 160 |
160 |
False |
160 (exit loop) |
At the end, the value of x is printed.
During then, x = 160.