The continue Statement

The continue statement is used in conjunction with the while, do...while, for, and for...in statements. The continue statement enables you to force the computer to perform another iteration.

Therefore, if the continue statement is placed directly in the body of a statement, all statements that follow are ignored. Here's an example:

<script language="JavaScript">
<!-- Cloaking device on!
var x = 0;
while (x < 10)
{
x++;
alert(x);
continue;
alert("You never see this!");
}
// Cloaking device off -->
</script>

This effect is generally undesirable, and it is far better to use the continue statement inside if statements. In this example, the alert box is bypassed when x = 5:

 <script language="JavaScript"> <!-- Cloaking device ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.