+ 3

if you don't use (break). which result will be executed

23rd Aug 2016, 2:54 PM
sagir
sagir - avatar
6 Respostas
+ 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"
24th Aug 2016, 9:18 AM
Zen
Zen - avatar
+ 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
23rd Aug 2016, 9:51 PM
HawkEye
HawkEye - avatar
+ 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?
24th Nov 2016, 6:55 AM
Rocket Master Yoda
Rocket Master Yoda - avatar
0
thanks my birader
24th Aug 2016, 11:46 AM
sagir
sagir - avatar
0
rica
25th Aug 2016, 7:59 AM
HawkEye
HawkEye - avatar
- 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.
13th Sep 2016, 7:31 AM
Prashanta Paul
Prashanta Paul - avatar