JavaScript Break Statement

break is special statement that can be used inside the loops, JavaScript break keyword terminates the current loop and execution control transfer after the end of loop.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript break with while loop</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
  var i = 0;
  while(i <= 10){
      if (i == 5){
          document.writeln("terminated, i = 5");
          break;
      }
      document.writeln(i);
      i++;
  }
</script>
</pre>
</body>
</html>

Run it...   »

Example Result