Break, next, and redo behavior
📖 Scenario: You are working on a simple program that processes a list of tasks. Sometimes you want to skip a task, stop processing early, or retry a task if it fails.
🎯 Goal: Build a Ruby program that demonstrates how to use break, next, and redo inside a loop to control the flow of task processing.
📋 What You'll Learn
Create an array called
tasks with the exact values: ['clean', 'cook', 'shop', 'laundry', 'study']Create a variable called
skip_task and set it to the string 'shop'Use a
for loop with variable task to iterate over tasks and inside the loop:Use
next to skip the task if it matches skip_taskUse
redo to retry the task 'laundry' once before moving onUse
break to stop the loop completely if the task is 'study'Print each task when it is processed
💡 Why This Matters
🌍 Real World
Controlling loops with break, next, and redo is useful when processing lists of jobs, filtering data, or retrying failed operations in real programs.
💼 Career
Understanding these flow controls helps in debugging, writing efficient loops, and managing complex workflows in software development.
Progress0 / 4 steps