Given the commands below what is the final value of z x 1 D
Given the commands below, what is the final value of z? x = 1 Do z = x*2 X = X + I If x > 4 Then Exit Do Loop
Solution
first iteration
z = 2 *1 = 2
x = 2;
x is less than 4 , so loop continue to execute
second iteration
z = 2*2 =4
x =3;
x is less than 4 , so loop continue to execute
third iteration
z = 2 * 3 =6
x = 4;
x is less than 4 , so loop continue to execute
fourth iteration
z = 2 * 4 =8
x = 5;
x is greater than 4 so execution breaks out of loop
so final value of z = 8
