ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.