DELAPARRA
Index
Color
NL
Category: Programming paradigms

Selection

Explained by Updated

What is Selection?

Selection: Branching logic — if/else, switch — choosing which block runs based on a condition. Selection is one of the three basic building blocks of structured programming, together with sequence and iteration. It means choosing which code to run based on a condition, using if, else, switch or match. Every business rule ends up as selection somewhere: free shipping above a certain amount, a different VAT rate for a country, access only for admins.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Selection

What should you keep in mind with Selection?

Keep conditions readable. Name complex conditions with a variable or method, such as $order->qualifiesForFreeShipping(), and return early to avoid deep nesting. When the same switch on a type appears in several places, polymorphism or a lookup table is usually cleaner. PHP's match expression is stricter and shorter than switch for mapping values, and it throws an error when no case matches.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with S

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.