if is faster than switch?
I was told by a teacher that a series of nested if statements is actually faster than a switch statement. According to a book he had read, a switch statement is only faster if there are 100 or more conditions. However, he was unsure of the reasoning behind it.
Can anyone verify/explain why this is true or not true?
Re: if is faster than switch?
Quote:
Originally posted by skorman00
I was told by a teacher that a series of nested if statements is actually faster than a switch statement. According to a book he had read, a switch statement is only faster if there are 100 or more conditions. However, he was unsure of the reasoning behind it.
Can anyone verify/explain why this is true or not true?
It's a sweeping generalisation that serves only to confuse. Ignore it.
By the way, can you tell us which book it was that said this, and provide a direct quote?