Loops Quiz


What is the value of num1 after the following?

num1 = 2
num2 = 0

while num2 < 7
     num1 = num1 + 3
    num2 = num2 + 1
end

Show Answer

Finish the code below with a while loop that will increment the variable num_dogs by 2 and decrement the variable num_cats by 1 until num_dogs is greater than num_cats.

num_dogs = 1
num_cats = 186

Show Answer

What will be the output of the following?

num = 0

while num < 8
    if num % 3 == 0
        puts(num)
    end
    num = num + 1
end

Show Answer