JS break和continue
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title></title>
6 </head>
7 <body>
8 </body>
9
10 <script type="text/javascript">
11 /*
12 * 1、break
13 * 作用:
14 * 1、跳出多选择分支 switch
15 * 2、结束循环(离它最近的)
16 */
17 var i = 5;
18 while(i > 0){
19 console.log(i);
20 i--;
21 if(2 == i){
22 break;
23 }
24 }
25 while(1){
26 console.log("hehe");
27 }
28
29 /* continue
30 * 作用:结束当次(本次)循环
31 */
32 var i = 0;
33 while(i < 5){
34 i++;
35 if(2 == i){
36 continue;
37 }
38 console.log(i);
39
40 }
41
42 //利用 continue 打印1-100之间的偶数
43 var i = 0;
44 while(i < 100){
45 i++;
46 if(i % 2 != 0){
47 continue;
48 }
49 console.log(i);
50
51 }
52
53 </script>
54 </html>