Learn JavaScript

JavaScript continue

To manipulate, JavaScript loops and switch statements / blocks, JavaScript provides the mechanism called JavaScript continue. Sometimes in a program, it may happen that we do not need to execute all the statements inside the loop statement or we do not need to perform all iterations. In such cases JavaScript continue allows the execution, to come out of the loop.

JavaScript continue, indicates the interpreter to start immediately the next iteration of the loop skip the execution of the remaining code snippet. While execution of a loop, when the control reaches continue the interpreter immediately transfer the control to the loop. If the truth value of the loop condition is true, then the next iteration started, otherwise the control leaves the loop, immediately for further execution.

Standard Syntax of JavaScript continue

Syntax

loop (loop statements)
{
Statements;
continue: label name;
}

Note: The continue is always used for decision making statements and label is optional with continue.


Example: JavaScript program to understand continue.

<html>
<body>
<h2>Program to understand the working of continue</h2>
<script>
var i;
for (i = 1; i < = 10; i++)
{
if (i==4)
{
continue;
}
document.write(i);
}
</script>
</body>
</html>

Output

Program to understand the working of continue

1
2
3
5
6
7
8
9
10

Explanation

When the value of the variable i becomes 4, the JavaScript continue skips the fourth iteration immediately. Then the value of i becomes 5 and the execution of loop continues to run, and rest of the values printed accordingly.


Audience

This JavaScript tutorial is designed to help the beginners as well as the professional developers. For better understanding the language of the tutorial is kept simple and easy to understand.

Prerequisites

This tutorial demands to have the basic knowledge of the programming languages such as c or c++, HTML, loops for the better understanding of the JavaScript programming language. The other basic requirement to learn JavaScript through this tutorial is the basic knowledge of computer and information technology so you can easily acquire a better understanding JavaScript programming.

Community Helping

In case you find any kind of error like typing error, spelling mistakes, incorrect grammar, incorrect information or any other mistakes. Please feel free to write to us at: akyadav@etutororg.com.