this is odd since you don't need to loop to find the answer

maxnum = 10_000

n = 2 ** (Math.log(maxnum) / Math.log(2)).floor

puts n + " is the largest power of 2 less than " + maxnum