New course! Every coder should learn Generative AI!
Try a free lesson0
The "if" statement only executes 1 block of code if the condition is true.
If the "if" statement condition returns false you can use an "else" statement that would be executed instead or "else if" statement to check for a new condition. The "if" statement is more for checking if conditions are true or false. On the other hand. The "switch" statement checks the specified expressions value and executes the block of code that matches. The "switch" statement COULD contain hundreds of different codes to check and execute for any particular values given.