Why is switch used and is alternate method for what? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Why is switch used and is alternate method for what?

19th Nov 2016, 9:40 AM
Haldhar Patel
Haldhar Patel - avatar
2 ответов
+ 3
switch is used as alternate method for multi if. Instead of write : if (a==onevalue)...... else if (a==othervalue) ,,, else if (a==otherothervalue)... ............................................... you can write one switch command with a several case branches..
19th Nov 2016, 9:53 AM
Petr Hatina
Petr Hatina - avatar
+ 2
switch is a multi conditional statement it can be used when we want to avoid the multiple use of too many if statements we can also use continue statement with it which is not allowed with if
19th Nov 2016, 1:45 PM
Programmer