Should I use return/continue statement instead of if-else?

前端 未结 13 1883
时光说笑
时光说笑 2020-12-01 10:46

In C, C++ and C# when using a condition inside a function or loop statement it\'s possible to use a continue or return statement as early as possible and g

13条回答
  •  北海茫月
    2020-12-01 11:15

    It depends a little on how long the branches are. The use of return/continue that you describe is good if the initial if check is short, and the body is long. If both if and else parts are long, I would extract them to separate functions.

    I recommend reading Code Complete, it discusses things like this a lot.

提交回复
热议问题