gpt4 book ai didi

javascript - 如何(中断;同时)和(继续;循环)

转载 作者:行者123 更新时间:2023-11-28 14:43:38 25 4
gpt4 key购买 nike

嗨,我有一个小问题,很难解释,但我在循环中有一段时间。

我的插件的上下文要求重置循环。 (继续)不过,我还需要暂时休息一下。

我如何打破这段时间并打电话继续;对于循环。

这里是完整的上下文,我知道很难从自定义上下文中读取代码但这里是我的函数范围和尝试的目标。

看看这一行console.log('=>如何中断并继续')感谢帮助

    // STEP3: BUILD TEXT CHILD
var re = /\w+.|\W/g; // \w+.\s*|\W+ // if wordWrap only
var l = -1; // START AT LINE -1 (line++ at start loop)
var lineX = 0;
var lineY = 0;
var lineHeight = 0; // at end maxheight auto increase
var newLine=true; // jmp line and creat
var dataLine = [];
var maxLineX = this._style.global.wordWrap && this._style.global.wordWrapWidth || false;
var pixiBox = false;;
for(var d=0, newLine=true; d<dataTxt.length; d++){ // loop all dataTxt

var data = dataTxt[d];
var dataL = dataLine[l];
if(newLine){ // INITIALISE NEW LINE AND RESET DATA
lineY+=lineHeight;
lineX = 0;
lineHeight = 0;
newLine = false;
l++;
dataLine[l] = {width:0, height:0, txtID:[], line:l }; // initialise a new this._dataLines [line]
var dataL = dataLine[l];
};

// create type of elements
if(!pixiBox){ // if empty pixi box, create new data pixi
if(data.type==='txt'){
pixiBox = new PIXI.Text(data.value, data.style);
}else if(data.type==='icon'){ // if icons was not registered, registe to pixiBox;
pixiBox = new PIXI.Sprite(pixiMS._iconsID[data.value]);
}else if(data.type==='jmp'){
pixiBox = new PIXI.Graphics();
pixiBox.drawRect(0, 0, 0, dataL.height+data.value);
newLine = true;
};
};



// check if its ou limit ?
if(maxLineX && (lineX + pixiBox.width) > maxLineX){
if(d>5000){confirm('ERROR EXCEED LIMIT WORDWRAP < WORD LENGTH, OR USE BREAK WORDS'); break; }; // protection freeze engine (win) if wrong wordWrap size
if(data.type==='icon'){newLine = true; d--; continue; }; // reset to a newLine, but keep icons registered

// its a text need Split to a new line;
var letterWidth = pixiBox.width / data.value.length; // calculate width of all letter
var tmpW = 0; // Temps Width
while ( (match = re.exec(data.value) ) !== null) {
var mL = match[0].length; // match txt length
if(lineX+tmpW+(mL*letterWidth) > maxLineX){ // if this match exeed , txt befor index become this valur and add extra data after
if(match.index===0){ // if match index 0 , (this data continue) reset new line
console.log('=> how break and continue');newLine = true; d--; break; continue;
}else{ // current txt become txt befor , and push new data after
data.value = match.input.slice(0, match.index); // text befor the match (if 0 its ok, just empty txt)
var after1 = this._newData('jmp', 0, "wordWrapBreak", false);
var after2 = this._newData('txt', match.input.slice(match.index), data.tag, data.style);
this._dataTxt.splice(d+1, 0, after1,after2); // reconfigu the loop length
pixiBox.text = data.value; // redefine pixi
break;
}

};
tmpW+=lineX;
};
};


data.xPos = lineX;
data.yPos = lineY;
data.line = l;

// INCREASE TXT POSITION
lineX += pixiBox.width; // x pos for next pixi element
dataL.width = lineX; // line width ++ valueOf()
lineHeight = pixiBox.height>lineHeight&&pixiBox.height||lineHeight;

dataL.height = lineHeight;
dataL.txtID.push(d);
this._childTexts.push(pixiBox); // store child array
this.addChild(pixiBox);
pixiBox = false;
};
return this;

编辑已解决:

        if(maxLineX && (lineX + pixiBox.width) > maxLineX){
if(d>5000){confirm('ERROR EXCEED LIMIT WORDWRAP < WORD LENGTH, OR USE BREAK WORDS'); break; }; // protection freeze engine (win) if wrong wordWrap size
if(data.type==='icon'){newLine = true; d--; continue; }; // reset to a newLine, but keep icons registered

// its a text need Split to a new line;
var letterWidth = pixiBox.width / data.value.length; // calculate width of all letter
var tmpW = 0; // Temps Width
var skip = false;
while ( (match = re.exec(data.value) ) !== null) {
var mL = match[0].length; // match txt length
if(lineX+tmpW+(mL*letterWidth) > maxLineX){ // if this match exeed , txt befor index become this valur and add extra data after
if(match.index===0){ // if match index 0 , (this data continue) reset new line
console.log('=> how break and continue');newLine = true; d--; skip=true; break;
}else{ // current txt become txt befor , and push new data after
data.value = match.input.slice(0, match.index); // text befor the match (if 0 its ok, just empty txt)
var after1 = this._newData('jmp', 0, "wordWrapBreak", false);
var after2 = this._newData('txt', match.input.slice(match.index), data.tag, data.style);
this._dataTxt.splice(d+1, 0, after1,after2); // reconfigu the loop length
pixiBox.text = data.value; // redefine pixi
break;
}

};
if(skip){continue;}
tmpW+=lineX;
};
};

最佳答案

您需要的是标签。

forloop:
for(){
whileloop:
while(){
break whileloop;
}
}

这将退出 while 循环,但仍保留在 for 循环中。在这里阅读更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

关于javascript - 如何(中断;同时)和(继续;循环),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47230995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com