continue

Passes control to the next iteration of the loop it’s running in, bypassing any remaining statements within that code block.

 

This example has the val variable initialised to a starting value of 4 and checks in the for loop if the value is greater than 6 AND less than 12, if not carry on, otherwise skip that iteration:

<html>
	<head>
		<title>JavaScript</title>
	</head>
	<body>
	<script type="text/javascript">
		var val ;

		for (val = 4; val < 15; val++) {

			if (val >= 6 && val <= 12 ){
				continue;
			}
			document.write("val = " + val + "<br>");
		}
	</script>
	</body>
</html>

Save & refresh browser:

val = 4
val = 5
val = 13
val = 14

Leave a Reply