← Back to archive

Stdle #72 · exceptions · 2026-08-17

What does this Ruby snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

attempts = 0
begin
attempts += 1
raise "fail" if attempts < 3
puts "ok on attempt #{attempts}"
rescue
retry if attempts < 3
end
Exceptions
4 attempts left

Answer & explanation