Hello, Sri.
If statement is used for small case in which we know the the possibilities are small and switch case are use for large possibilities because the switch take more time to run as if statement. Switch looks better and you can use a default return value in case none meet the condition . Just be careful with the breaks if not it will break you.
Hi, Switch and if condition is same but the big difference is that when a computer comes to an if condition statement..it goes through all the condition to give results, giving to a waste of time but switch statement doesn’t make a computer waste time in decision-making process cuz it doesn’t go through all of it but goes straight to the point at which it’s true.
Question and answer is powered by AnsPress.io