whiledef self.years_before_desired_balance(current_balance, desired_balance)
years = 0
while current_balance < desired_balance
current_balance = annual_balance_update(current_balance)
years += 1
end
years
end
untildef self.years_before_desired_balance(current_balance, desired_balance)
years = 0
until current_balance >= desired_balance
current_balance = annual_balance_update(current_balance)
years += 1
end
years
end
loopdef self.years_before_desired_balance(current_balance, desired_balance)
years = 0
loop do
current_balance = annual_balance_update(current_balance)
years += 1
return years if current_balance >= desired_balance
end
end
जैसा कि आपने शायद ध्यान दिया होगा, Ruby में बढ़ाने वाला ऑपरेटर (i++) नहीं है, जबकि कुछ अन्य भाषाओं में होता है। इसके बजाय i += 1 जैसी चीज़ें इस्तेमाल की जा सकती हैं, जो i = i + 1 के बराबर होती हैं।