Loop ဆိုတာ code တစ်ပိုင်းကို ထပ်ခါထပ်ခါ run စေတဲ့နည်းလမ်းပါ။ Ruby မှာ while, until ရှိပေမယ့် collection တွေအတွက် each ကို ပိုသုံးလေ့ရှိပါတယ်။
ruby
count = 1
while count <= 3
puts "While count: #{count}"
count += 1
end
counter = 1
until counter > 3
puts "Until counter: #{counter}"
counter += 1
endwhile က condition မှန်နေသရွေ့ run ပါတယ်။ until က condition မမှန်သရွေ့ run ပါတယ်။ Loop တိုင်းမှာ counter ကို update မလုပ်ရင် infinite loop ဖြစ်နိုင်ပါတယ်။
You should see
While count: 1 While count: 2 While count: 3 Until counter: 1 Until counter: 2 Until counter: 3Info
count += 1 သည် count = count + 1 နဲ့တူပါတယ်။