JavaScript
x
25
25
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8">
5
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<title>Document</title>
8
</head>
9
<body>
10
<head>LOOPS</head>
11
<h1 id="string"></h1>
12
<script language="javascript" type="text/javascript">
13
let w = 10;
14
while (w <= 15) {
15
console.log(w);
16
17
if (w == 12) {
18
continue;
19
}
20
w++;
21
}
22
</script>
23
</body>
24
</html>
25
This creates an infinite loop, But I’m trying to skip 12, if I remove the increment it doesn’t display at all.
Advertisement
Answer
You need to increase w
value before you do the skipping, one method is to do it inside the while
condition:
JavaScript
1
8
1
let w = 9;
2
while(++w<=15){
3
4
if(w==12){
5
continue;
6
}
7
console.log(w)
8
};