This is related to a chapter from beautiful code.
And in that chapter I read about the nested if
s.
The author was talking about deeply nested if
s as originator of bugs and less readable.
And he was talking about replacing nested if
s with case
statements and decision tables.
Can anybody illustrate how to remove nested if
s with case
(select case
) and decision tables ?
Well, not directly an answer to your question since you specifically ask about switch/case statements, but here is a similar question.
Invert “if” statement to reduce nesting
This talks about replacing nested if's with guard-statements, that return early, instead of progressively checking more and more things before settling on a return value.