非法继续:Javascript
Illegal Continue: Javascript
我有两个 for 循环检查两组项目。我有以下代码:
for(var key in powder){
for(var key2 in powder){
if(key == key2){ continue; };
[...]
}
[...]
}
([...]是不重要的信息。)
但是,javascript 给我一个错误:Uncaught SyntaxError: Illegal continue statement
而且我不知道为什么!我已经检查了多个资源(W3Schools、Whosebug 等),但没有任何资源。请帮忙!
在 js 中尝试了类似的代码并且工作正常。可能是你没有的代码行有问题 post 或者你的 powder 变量有问题
<html>
<script>
function fun(){
var powder =[1,2,4,5];
for(var key in powder){
for(var key2 in powder){
if(key == key2){ alert("con");continue; };
}
}
}
</script>
<body onload="fun()"></body>
</html>
以下代码将导致非法继续 statement.The continue 语句必须出现在循环中,而不是出现在被调用的函数中。
<html>
<script>
function funOne(){
for(var i=0;i<10;i++){
fun();
}
}
function fun(){
if(1==1){ //this line is the cause of error
continue;
}
var powder =[1,2,4,5];
for(var key in powder){
for(var key2 in powder){
if(key == key2){ alert("con");continue; };
}
}
}
</script>
<body onload="funOne()"></body>
</html>
我有两个 for 循环检查两组项目。我有以下代码:
for(var key in powder){
for(var key2 in powder){
if(key == key2){ continue; };
[...]
}
[...]
}
([...]是不重要的信息。)
但是,javascript 给我一个错误:Uncaught SyntaxError: Illegal continue statement
而且我不知道为什么!我已经检查了多个资源(W3Schools、Whosebug 等),但没有任何资源。请帮忙!
在 js 中尝试了类似的代码并且工作正常。可能是你没有的代码行有问题 post 或者你的 powder 变量有问题
<html>
<script>
function fun(){
var powder =[1,2,4,5];
for(var key in powder){
for(var key2 in powder){
if(key == key2){ alert("con");continue; };
}
}
}
</script>
<body onload="fun()"></body>
</html>
以下代码将导致非法继续 statement.The continue 语句必须出现在循环中,而不是出现在被调用的函数中。
<html>
<script>
function funOne(){
for(var i=0;i<10;i++){
fun();
}
}
function fun(){
if(1==1){ //this line is the cause of error
continue;
}
var powder =[1,2,4,5];
for(var key in powder){
for(var key2 in powder){
if(key == key2){ alert("con");continue; };
}
}
}
</script>
<body onload="funOne()"></body>
</html>