Home »
JavaScript
JavaScript | Example of jumping statement (break, continue)
Example of jumping statement (break, continue) in JavaScript: Here, we are going to learn about break and continue statement with examples in JavaScript.
Submitted by Pankaj Singh, on October 18, 2018
1) break statement
It is used to break the loop's execution; it transfers the execution next statement after the loop.
Example of break statement
<!DOCTYPE html>
<html lang="en">
<head>
<script>
for(var i=1;i<=10;i++){
if(i==7){
break;
}
document.write(i+"<br />");
}
</script>
</head>
<body>
</body>
</html>
Output
1
2
3
4
5
6
2) continue statement
It is used to continue the loop's execution, it transfers the execution to the loop by escaping the written statement in the loop body after the continue statement.
Example of continue statement
<!DOCTYPE html>
<html lang="en">
<head>
<script>
for(var i=1;i<=10;i++){
if(i==7){
continue;
}
document.write(i+"<br />");
}
</script>
</head>
<body>
</body>
</html>
Output
1
2
3
4
5
6
8
9
10
JavaScript Tutorial »