0
What will be happen if not put break statement in switch case?
Any guess
7 Respostas
+ 4
Let's says you have 3 stages in your switch case;without break if first condition fits all these 3 stages will performed.
But you use switch to do specific action for specific conditions so when programme see this it should do and break out from switch.
the example below is just for you to understand typo depends on language
switch grade:
case a:
print "excellent";
break:
case b:
print "good work";
break:
case c:
print "better next time";
break:
case d:
print "not bad";
break:
case e:
print "work harder";
break:
default:
print "failed";
if you don't use break it will display all messages.
https://code.sololearn.com/cpYJQ8X6J0Y6/?ref=app
+ 2
Just try it ;)
https://code.sololearn.com/cDS60Ylxts2N/?ref=app
+ 2
Without break statement if any condition is satisfied then all the statement below it will also be printed on screen.
+ 2
Stack overflow - infinite loop 😡
+ 1
If we don't use break statement in switch case then fall through ocuurs
And entire program get executed
Until compiler finds break statement
- 1
Sanjay Kamath by switch you can not have infinite loop