Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4df056

Browse files
Break & Continue in JS 😁✨
1 parent 97efdd6 commit d4df056

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Hello World!</title>
7+
</head>
8+
<body>
9+
10+
<script src="./script.js"></script>
11+
12+
</body>
13+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
alert("Break & Continue in JS!");
2+
3+
/*
4+
5+
JavaScript Break and Continue
6+
The break statement "jumps out" of a loop.
7+
8+
The continue statement "jumps over" one iteration in the loop.
9+
10+
The Break Statement
11+
You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch() statement.
12+
13+
The break statement can also be used to jump out of a loop:
14+
15+
Example
16+
for (let i = 0; i < 10; i++) {
17+
if (i === 3) { break; }
18+
text += "The number is " + i + "<br>";
19+
}
20+
In the example above, the break statement ends the loop ("breaks" the loop) when the loop counter (i) is 3.
21+
22+
23+
The Continue Statement
24+
The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
25+
26+
This example skips the value of 3:
27+
28+
Example
29+
for (let i = 0; i < 10; i++) {
30+
if (i === 3) { continue; }
31+
text += "The number is " + i + "<br>";
32+
}
33+
34+
*/
35+
36+
for (let i = 0; i < 10; i++) {
37+
38+
if(i === 5 || i === 3) {
39+
document.write("<br />Loop skip execution of Number " + i + " :: Because continue statement!");
40+
continue; // When code come to this loop will not excute below any lines loop continue to go with next number of iteration
41+
}
42+
43+
document.write("<br />Number: " + i);
44+
if (i === 7) {
45+
document.write("<br />Number is equal to 7 so loop breaked using break statement! 🍳 : LOOP NO LONGER EXECUTE!");
46+
break;
47+
}
48+
}
49+
50+
document.write("<br /><br />All links are now looped!");

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /