+ 3
if you don't use (break). which result will be executed
6 Answers
+ 7
If you forget to add breaks to your switch cases, you will enter the matching case plus all the cases beneath it.
var x = 2;
switch(x){
case 1:
document.write("1");
case 2:
document.write("2");
case 3:
document.write("3");
}
//outputs "23"
+ 2
kardes break kullanilmazsa dongu devam eder. ornek. var i;
for( i = 0 ; i < 5 i++){
if(i ==3);}
break; //dongu son bulur.
eger continue kullanirsan 5 e kadar devam eder
+ 1
so how can you execute only certain cases, for example i have list of 5 cases and i want to execute only those that are true. if i keep break in every case, there will be only one result, if i remove all breaks, there will be more results than it was supposed to be. or maybe for this example i should use else if?
0
thanks my birader
0
rica
- 2
It simply go for all the code unnecessarily though the program will be unaffected and it print after the first condition true switch, then all one by one.