您能向我解释一下 如何在与断线互动的语句上使用标签吗? 切换,同时切换,同时切换,同时切换,同时切换,并用于。
请使用示例 。
您能向我解释一下 如何在与断线互动的语句上使用标签吗? 切换,同时切换,同时切换,同时切换,同时切换,并用于。
请使用示例 。
通常,我在:
var i, j;
dance: for (i = 0; i < 20; i++) {
for (j = 0; j < 20; j++) {
console.log(i+ - +j);
if (j === 10) { //normally, break only breaks the immediate loop
break dance; //this one breaks the loop labelled as dance
}
}
}
//continue here after i = 0,j = 10
com/2007/03/09/the-javascript-goto-statement/"rel="nofollow" article 。
文章中的联署材料法典:
var pastures = getPastures();
var i, pastureLen = pastures.length;
pastureLoop:
for (i = 0; i < pastureLen; i++)
{
var pasture = pastures[i];
var cows = pasture.getCows();
var j, numCows = cows.length;
for (j = 0; j < numCows; j++)
{
var cow = cows[j];
if (cow.isEating())
{ continue pastureLoop; }
}
// No cows were eating, so fire the callback for pasture[i]
pasture.executeCallback(); // or whatever
}
查询Mozilla开发者网络 < a href="https:// developmenter.mozilla.org/en/JavaScript/Reference/ Statements/ label" rel="Nofollow noreferrer" >Language Reference :
提供带有标识符的语句,您可参考该语句使用中断或继续使用语句。
例如,您可以使用标签来识别循环,然后使用中断或继续语句来表示一个程序是中断循环还是继续执行循环。
请注意,他们也说:
JavaScript 使用标签并不常用 JavaScript, 因为这些标签使程序更难阅读理解。 尽可能避免使用标签,并视具体情况, 更喜欢调用功能或丢弃错误
不使用标签 。
示例:
// no label
while (condition) {
// do something
}
label:
( 标签语句
),基本上用于断开或继续断开或延续语句的语句,这些语句有助于断开或继续贴上标签的语句,与普通的 break
语句不同,这些语句只打破即时循环。
让我以演示语解释 break
和 continue
。
断开 < 强 > : 强 >
let i, j;
loop1:
for (i = 0; i < 3; i++) {
loop2:
for (j = 0; j < 3; j++) {
if (i === 1 && j === 1) {
break loop1; // terminate the whole loop labelled as loop1 unline normal break which will only terminate the current loop)
}
console.log( i = + i + , j = + j);
}
}
继续<强>: 强>
let str = ;
loop1:
for (let i = 0; i < 5; i++) {
if (i === 1) {
continue loop1; // This statement will again run the loop labelled as loop1
}
str = str + i;
}
console.log(str); // 0234
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.