Break and continue behavior
📖 Scenario: Imagine you are organizing a small party and you have a list of guests with their ages. You want to invite only adults (age 18 and above) but stop checking guests once you find a guest who is under 10 years old, as they are too young for the party.
🎯 Goal: You will write a Swift program that uses break and continue statements to process the guest list. You will skip guests who are under 18 but continue checking others, and stop the process entirely if a guest is under 10.
📋 What You'll Learn
Create a dictionary called
guests with these exact entries: "Alice": 25, "Bob": 17, "Charlie": 9, "Diana": 30, "Eve": 20Create an empty array called
invitedGuests to store names of guests who are invitedUse a
for loop with variables name and age to iterate over guestsInside the loop, use
continue to skip guests younger than 18Inside the loop, use
break to stop the loop if a guest is younger than 10Add the guest's
name to invitedGuests if they are 18 or olderPrint the
invitedGuests array at the end💡 Why This Matters
🌍 Real World
This project simulates filtering a list of people based on age criteria, which is common in event planning, marketing, or user management.
💼 Career
Understanding break and continue is important for controlling loops efficiently in many programming tasks, such as data processing, filtering, and early exit conditions.
Progress0 / 4 steps