Both forms choose among alternatives, but they test conditions in different ways.
Else-if ladder
Each branch can test a different condition. Conditions may use relational and logical operators, such as marks >= 90 or age >= 18 && has_id. Conditions are checked in order until one is true. Only that branch executes. A final else can handle the remaining cases.
Switch
One integer expression is compared with integer constant case values. This makes numbered menus or character-based operation choices clear. A default label handles a missing match. Case labels do not stop execution; a break or another transfer is normally used to prevent unwanted fall-through.
Examples
Use an else-if ladder to classify marks into ranges such as 90–100 and 75–89.
Use switch to process a menu choice such as 1 for Add, 2 for View and 3 for Exit.
For two simple alternatives, a plain if-else is usually sufficient.
Choice and efficiency
Choose the form that expresses the actual condition clearly. An else-if ladder may perform up to k tests for k conditions. A switch is not guaranteed by C to be faster: the compiler chooses an implementation. For a small fixed decision, both may involve only constant work. Correct logic and readability matter more than assuming one keyword always improves speed.
Comparison table
↔ Scroll horizontally on a small screen
Else-if ladder and switch
Feature
Else-if ladder
switch
Condition
Separate conditions, including ranges
One integer expression and constant case values
Branch control
First true branch only
Starts at matching label; may fall through
Remaining cases
Final else
default label
Typical use
Grades, eligibility ranges
Menus, operator choices
Related exam questions
Related questions in the selection category from the supplied papers. The marks below are the printed allocations, including any combined subquestion.
March/April 2023 · Q3(a) · 5 marks
Discuss decision-making statements with an example.
Paper P02 · page 1
June 2022 · Q2(b) · 8 marks
Illustrate forms of if statements with syntax and examples.