I've read that you should only typically use switch statements if your logic is simplistic and if, elseif, else when dealing with more complex logic. Would you agree or disagree?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 23, 2014, 8:39 AM
You can only switch on integers, characters, strings or enums and, if you need to specify a range of values, then you have to stack cases on top of each other which is clearly only viable where the range is very small.
So, yes, I'd agree that the situations where switch can be used are quite limited and most of the time you have to use an if/else if/else ladder instead.
In fact, I know some programmers who avoid switch altogether because they feel that having to put 'break' or a similar jump statement at the end of each case makes it unnecessarily verbose.