Compare the if statement and switch statment | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Compare the if statement and switch statment

29th Apr 2017, 6:17 AM
Zeyad Sharo
Zeyad Sharo - avatar
4 Respostas
+ 10
The if statement tests a condition. The switch statement tests a variable for equality against different values.
29th Apr 2017, 6:26 AM
The Unknown
The Unknown - avatar
+ 8
if is slower than switch as for switch-case, compiler directly pass to the required value.In if, it check for each if part and verifies if it is true of false. switch cannot handle difficult expressions .Example šŸ¤“, case 'x+7' is not valid, if can.
29th Apr 2017, 6:31 AM
Meharban Singh
Meharban Singh - avatar
+ 3
How?
29th Apr 2017, 6:21 AM
CalviÕ²
CalviÕ² - avatar
+ 1
In terms of code
29th Apr 2017, 6:22 AM
Zeyad Sharo
Zeyad Sharo - avatar