i get reference from here "How can I use goto in Javascript?"
i understand the code as below
[lbl] first:
alert("Test")
goto first;
however. why the code below does not work for me
goto end;
alert("skipped line");
[lbl] end:
when I run the above mand I will get an error like this
i get reference from here "How can I use goto in Javascript?"
i understand the code as below
[lbl] first:
alert("Test")
goto first;
however. why the code below does not work for me
goto end;
alert("skipped line");
[lbl] end:
when I run the above mand I will get an error like this
Share Improve this question edited May 23, 2017 at 11:54 CommunityBot 11 silver badge asked Jun 24, 2015 at 2:27 Error PersonError Person 331 gold badge1 silver badge4 bronze badges 6-
Because
end
is not a label. Labels in JavaScript have the formlabel: statement
(granted the preprocessing tool might be able to handle that case, but apparently it does not). – Felix Kling Commented Jun 24, 2015 at 2:28 -
[lbl] end: ;
might work.end:
is the label and;
is the empty statement. – Felix Kling Commented Jun 24, 2015 at 2:35 - sorry i misstype. i update my questions – Error Person Commented Jun 24, 2015 at 2:39
-
3
Well the obvious ment here is to never use
goto
in the first place. It's considered an evil construct by many. Instead, use conditionals, loops, functions, methods and return statements to construct your flow. – jfriend00 Commented Jun 24, 2015 at 2:44 - i still not understand what evil? :v – Error Person Commented Jun 24, 2015 at 2:53
1 Answer
Reset to default 2Labels are for loops and blocks.
Loop usage:
var allPass = true
top:
for(var i=0; i < items.length; ++i)
for(var j=0; j < tests.length; ++j)
if(!tests[j].pass(items[i])){
allPass = false
break top
}
You can also use continue label
.
Block usage:
foo: {
console.log("face")
break foo
console.log("this will not be executed")
}
console.log("swap")
Non-strict, non-generator, function usage:
L: function F(){}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745436705a4627639.html
评论列表(0条)