Replacing nested if statements

前端 未结 11 1926
春和景丽
春和景丽 2020-12-23 20:44

This is related to a chapter from beautiful code. And in that chapter I read about the nested ifs.

The author was talking about deeply nested if

11条回答
  •  感动是毒
    2020-12-23 21:32

    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.

提交回复
热议问题