-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakcontinue.html
More file actions
32 lines (28 loc) · 1021 Bytes
/
breakcontinue.html
File metadata and controls
32 lines (28 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // 0 - 9
let count = numbers.length;
// continue 跳過本次迴圈
// break 跳出迴圈
for (let i = 0; i < count; i++) { // 初始 ; 條件 ; 更新
if (numbers[i] % 2 == 0) { // 偶數
document.write(numbers[i] + "是偶數<br>");
document.write(numbers[i] + " "+ i.toString() + " before continue<br>");
// continue; // 跳過本次迴圈
document.write(numbers[i] + " "+ i.toString() + " after continue<br>");
if (numbers[i] == 6) {
break;
}
}
//document.write(numbers[i] + "是奇數<br>");
}
</script>
</body>
</html>