what the difference between break with label and without label in javascript
Posted
by
dramasea
on Stack Overflow
See other posts from Stack Overflow
or by dramasea
Published on 2011-02-25T15:20:21Z
Indexed on
2011/02/25
15:24 UTC
Read the original article
Hit count: 408
<script type="text/javascript">
var num = 0;
for(var i = 0; i < 10; i++){
for(var j = 0; j < 10 ; j++){
if(i == 5 && j == 5){
break;
}
num++;
}
}
alert(num);
</script>
In the above code,i expect the result to be 55 but why the result is 95.
But why if i added that the label, the result become 55?Can someone tell me thanks!!
<script type="text/javascript">
var num = 0;
outermost:
for(var i = 0; i < 10; i++){
for(var j = 0; j < 10 ; j++){
if(i == 5 && j == 5){
break outermost;
}
num++;
}
}
alert(num);
</script>
© Stack Overflow or respective owner