Ruby স্ট্যান্ডার্ড control-flow (if, , ) অফার করে কিন্তু বিশেষভাবে স্বতন্ত্র এবং প্রকাশনী বৈশিষ্ট্য সহ: (), , শক্তিশালী , এবং ঐতিহ্যবাহী লুপের চেয়ে এর পছন্দ। Ruby তে control flow প্রাকৃতিকভাবে পড়া যায়।
casewhiledo_x if conditionunlesscase/whenif age >= 18
puts "adult"
elsif age >= 13
puts "teen"
else
puts "child"
end
# MODIFIER form — condition at the END (reads like English, idiomatic for short cases)
puts "adult" if age >= 18
puts "minor" unless age >= 18 # `unless` = if not (more readable than `if !`)
# everything is an expression — if returns a value
grade = if score >= 90 then "A" else "B" end
Ruby এর modifier form (puts "x" if condition) শর্তকে শেষে রাখে সংক্ষিপ্ত, পাঠযোগ্য one-liners এর জন্য। unless (= "if not") negation এর চেয়ে আরও স্বাভাবিকভাবে পড়া যায়। এবং if একটি expression যা একটি value ফেরত দেয়।
case status
when :active then "running"
when :stopped, :paused then "halted" # multiple values
when 1..10 then "small number" # ranges
when String then "it's a string" # types (uses ===)
else "unknown"
end
# case can also do structural pattern matching (Ruby 3)
case data
in { name: String => name, age: Integer } # pattern matching with destructuring
puts name
end
Ruby এর case/when শক্তিশালী — এটি values, ranges, types, এবং (Ruby 3 তে) structural patterns match করে, হুডের অধীনে === ব্যবহার করে। একটি বেসিক switch এর চেয়ে অনেক বেশি নমনীয়।
while count < 10 do count += 1 end
until done do ... end # until = while not
# ✅ but Ruby PREFERS iteration with blocks over explicit loops:
5.times { |i| puts i } # instead of a for loop
[1, 2, 3].each { |n| puts n } # iterate a collection
(1..10).each { |n| ... } # iterate a range
1.upto(5) { |i| ... }
Ruby এর কাছে while/until আছে, কিন্তু idiomatic Ruby explicit loops এর চেয়ে blocks সহ iteration পছন্দ করে (each, times, map) — আরও প্রকাশনী এবং Ruby-সদৃশ।
Ruby এর control flow বুঝা মৌলিক দৈনন্দিন জ্ঞান, এবং বেশ কয়েকটি বিশেষ বৈশিষ্ট্য Ruby এর প্রকাশনী, পাঠযোগ্য দর্শনকে প্রতিফলিত করে।
Modifier form (do_x if condition) এবং unless (= "if not") আপনাকে সংক্ষিপ্ত, ইংরেজি-সদৃশ conditionals লিখতে দেয় যা idiomatic Ruby এবং ক্রমাগত প্রদর্শিত হয়।
এই যে if একটি expression (একটি value ফেরত দেয়) তা মার্জিত assignments সক্ষম করে।
Ruby এর case/when উল্লেখযোগ্যভাবে শক্তিশালী — values, ranges, types, এবং (Ruby 3 তে) === এর মাধ্যমে structural patterns match করে — এটিকে একটি বেসিক switch এর চেয়ে অনেক বেশি নমনীয় এবং পরিষ্কার multi-way branching এর জন্য উপযোগী করে তোলে।
মূলত, idiomatic Ruby traditional for/while loops এর চেয়ে blocks সহ iteration পছন্দ করে (each, times, map, upto) — এটি একটি সংজ্ঞায়িত stylistic পয়েন্ট: Ruby developers collections এবং ranges এর সাথে block-based methods দিয়ে iterate করে explicit loops এর পরিবর্তে, যা আরও প্রকাশনী এবং Ruby-সদৃশ।
এই constructs এবং idioms বোঝা — পাঠযোগ্য conditionals এর জন্য modifier form এবং unless, শক্তিশালী case/when, এবং বিশেষত explicit loops এর উপর block-based iteration এর পছন্দ — idiomatic Ruby লেখা এবং পড়ার জন্য গুরুত্বপূর্ণ।
যেহেতু control flow প্রতিটি প্রোগ্রামে প্রদর্শিত হয়, এবং যেহেতু Ruby এর প্রকাশনী forms (modifiers, unless, শক্তিশালী case, block iteration) এর পাঠযোগ্যতা-কেন্দ্রিক দর্শন প্রতিফলিত করে, তাদের আয়ত্ত করা অপরিহার্য, প্রাকৃতিক, idiomatic Ruby লেখার জন্য মৌলিক জ্ঞান অন্যান্য ভাষা থেকে loop-heavy patterns অনুবাদ করার পরিবর্তে।