Return & Break Quiz


What is the difference between return and break?

Show Answer

What is returned on the last line below?

def test_method(arr)
    ind = 0
    while ind < arr.length
        if arr[ind] % 5 == 0
            break
        else
            arr[ind] = 5
        end

        ind = ind + 1
    end

    ind = 0

    while ind < arr.length
        if arr[ind] % 10 == 0
            return arr
        else
            arr[ind] = 10
        end

        ind = ind + 1        
    end
end

test_method([2, 6, 17, 15, 6, 80, 19, 20])

Show Answer

Write a method, print_until_empty, that will take in a string and print out every letter until an empty space is encountered?

Show Answer