লু

লুপ মধ্যে Ruby

23টি অনুশীলনী

লুপ সম্পর্কে

while

def 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

until

def 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

loop

def 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 লেখার সমান) এ ধরনের গঠন ব্যবহার করা যায়।

GitHub-এর মাধ্যমে সম্পাদনা করুন লিংকটি নতুন একটি উইন্ডো বা ট্যাবে খুলবে

লুপ শিখুন

অনুশীলন লক করা আছে

লুপ অনুশীলন করতে আরও 10টি অনুশীলনী আনলক করুন