Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript break statement :  Example-1</title>
</head>
<body>
<h1 style="color: red">JavaScript : break statement</h1>
<script src="break-statement-example1.js"></script>
</body>
</html>
 
x = prompt("Input a number between 2 to 10 :");
if (x<2 || x>10)
{
alert('The number is not within the range.');
}  
else
{
var z = 0;
for(y=1; y<=x; y++)
{
z = z + y ;
if(y==x)
{
break;
}
}
alert('The sum of numbers between  1 to '+ x +' is: '+ z);
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x