/

HTML / CSS / JavaScript Tutorial

JavaScript Statement: continue

[this page | pdf | back links]

In JavaScript, the continue statement breaks an iteration (in a loop) if a specific condition occurs, moving on to the next iteration.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
document.getElementById("Example").innerHTML =
  'var i; var x = 0;<br>' +
  'for (i=1; i&lt;=4; i++) {<br>' +
  '&nbsp;&nbsp;if (i===3) { continue }<br>' +
  '&nbsp;&nbsp;x = x + i;<br>' +
  '}';
var i; var x = 0;
for (i=1; i<=4; i++) {
  if (i===3) { continue }
  x = x + i;
}
document.getElementById("Result").innerHTML = x;
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Reserved Words


Desktop view | Switch to Mobile