- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is continue statement in JavaScript?
The continue statement tells the interpreter to immediately start the next iteration of the loop and skip the remaining code block. The break statement is used to exit a loop early, breaking out of the enclosing curly braces.
When a continue statement is encountered, the program flow moves to the loop check expression immediately and if the condition remains true, then it starts the next iteration, otherwise, the control comes out of the loop.
You can try to run the following to learn how to work with continue statement in JavaScript. This example illustrates the use of a continue statement within a while loop. Notice how to continue statement is used to skip printing when the index held in variable x reaches 5 −
Example
<html> <body> <script> var x = 1; document.write("Entering the loop <br /> "); while (x < 10) { x = x+ 1; if (x== 5) { continue; // skip rest of the loop body } document.write( x + "<br />"); } document.write("Exiting the loop!<br /> "); </script> </body> </html>
Advertisements