WDTPD - Looping

8 questions

Q1
What is the output?
x = 1
FOR i = 1 TO 5
    x = x * 2 + 1
NEXT
OUTPUT: x
Q2
What is the output?
n = 7
count = 0
WHILE n != 1
    IF n MOD 2 == 0 THEN
        n = n / 2
    ELSE
        n = 3 * n + 1
    END IF
    count = count + 1
END WHILE
OUTPUT: count
Q3
How many times does the inner loop body execute?
FOR i = 1 TO 3
    FOR j = 1 TO 3
        IF i != j THEN
            (body)
        END IF
    NEXT
NEXT
Q4
What is the output?
n = 583
sum = 0
WHILE n > 0
    sum = sum + n MOD 10
    n = INT(n / 10)
END WHILE
OUTPUT: sum
Q5
What is the output?
p = 1
FOR i = 5 TO 1 STEP -1
    p = p * i
NEXT
OUTPUT: p
Q6
What is the output?
count = 0
FOR i = 1 TO 4
    FOR j = i TO 4
        count = count + 1
    NEXT
NEXT
OUTPUT: count
Q7
What is the output?
s = 0
FOR i = 1 TO 6
    IF i MOD 2 == 0 THEN
        s = s + i
    END IF
NEXT
OUTPUT: s
Q8
What is the output?
a = 0
b = 1
FOR i = 1 TO 6
    temp = b
    b = a + b
    a = temp
NEXT
OUTPUT: b