What if you could skip all the extra checks and only loop through exactly what you need?
Why For-in with where clause in Swift? - Purpose & Use Cases
Imagine you have a big list of customer orders and you want to find only the orders that are over $100. Doing this by hand means checking each order one by one and writing extra code to skip the ones you don't want.
Manually checking each item is slow and easy to mess up. You might forget to skip some orders or write extra loops that make your code messy and hard to read.
The 'for-in with where clause' lets you loop through items but only pick the ones that match your condition. This keeps your code clean and focused, so you don't waste time on unwanted data.
for order in orders { if order.amount > 100 { print(order) } }
for order in orders where order.amount > 100 { print(order) }
This lets you quickly and clearly work only with the data you care about, making your code simpler and faster to write.
Say you run a store and want to send a thank-you note only to customers who spent more than $100. Using 'for-in with where' helps you pick those customers easily without extra steps.
Manually filtering data is slow and error-prone.
'For-in with where clause' filters items during looping.
It makes code cleaner, easier, and faster to write.