Picture this: You're the Chief Architect of a booming digital city. Every day, building proposals land on your desk. Some are tiny cafés, others are towering skyscrapers. Your job? Evaluate each proposal and stamp it: APPROVED or REJECTED.
In C#, the if, else if, and else statements are your decision stamps. They let your program choose different paths based on conditions — just like an architect choosing different blueprints based on the terrain.
The simplest decision: "Is this condition true? If so, do something."
What if the condition is false? The else block catches everything that didn't match:
Real architectural reviews aren't just "tall or not." There are grades, tiers, and categories. That's where else if comes in — it lets you check multiple conditions in sequence:
Every if statement needs a condition. Here are the comparison operators the architect uses to evaluate proposals:
== — Equal to: floors == 10 → Are there exactly 10 floors?!= — Not equal to: material != "Wood" → Is it NOT made of wood?< — Less than: budget < 1000000 → Is the budget under a million?> — Greater than: floors > 50 → More than 50 floors?<= — Less than or equal: height <= 200 → At most 200 meters?>= — Greater than or equal: floors >= 20 → At least 20 floors?Sometimes one decision leads to another — like checking both height AND material strength. You can nest if statements inside each other:
= (assignment) instead of == (comparison) — the compiler will catch this for non-boolean types, but watch out!{} — without them, only the next single line belongs to the if block. Always use braces!else if chains — put the most specific conditions first. If you check floors > 5 before floors > 50, the 50-floor building matches the first condition and never reaches the second.The city council needs a building classification system. Given a building with a specific number of floors, your program must output three things: its approval status, the floor count, and the building category. Time to build that decision tree, Architect!