A conditional expresses a decision
An if statement runs code only when its condition is true. An else branch handles the other case. Keep the condition close to the user-visible decision so the behavior stays easy to read.
A loop handles a collection
A loop visits each item without repeating the same statement manually. Array methods such as map, filter, and find often express common collection work more clearly than a general loop.
A familiar example
Showing search results
- If the query is empty, show the complete list.
- Filter the lessons when the query has text.
- If the filtered list is empty, show one clear recovery message.
What to remember
- Conditionals connect facts to behavior.
- Loops remove repeated code for collections.
- Choose the clearest construct, not the most clever one.