Skip to main content

loop 循环

loop

类型: MethodDeclaration

所属类: CommandFunctionList

定义位置: command.ts

描述

循环

参数

参数名类型描述默认值
\{mode, conditions, commands\}`{
mode: string
conditions: Array<object>
commands: CommandDataList
}`--

返回值

类型: CommandFunction \| null

源代码

位置: 第 2890 行

protected loop({mode, conditions, commands}: {
mode: string
conditions: Array<object>
commands: CommandDataList
}): CommandFunction | null {
if (commands.length === 0) {
return null
}
const cmdpath = this.stack[0].path
const context = this.stack.get()
const nextCommands = context.commands
const nextIndex = context.index + 1
let infiniteLoopTest = Function.empty
if (Stats.debug) {
let timestamp = 0
let cycleCount = 0
infiniteLoopTest = () => {
if (timestamp !== Time.timestamp) {
timestamp = Time.timestamp
cycleCount = 1
} else if (++cycleCount > 100000000) {
CommandList = nextCommands
CommandIndex = nextIndex
console.error(`The number of loops exceeds 100000000, it may be an infinite loop.\n${cmdpath}`)
}
}
}
if (conditions.length !== 0) {
const tester = Command.compileConditions(mode, conditions)
const loopCommands = Command.compile(commands, () => {
if (tester()) {
CommandIndex = 0
infiniteLoopTest()
} else {
CommandList = nextCommands
CommandIndex = nextIndex
}
return true
}, true)
return () => {
if (tester()) {
CommandList = loopCommands
CommandIndex = 0
}
return true
}
} else {
const loopCommands = Command.compile(commands, () => {
CommandIndex = 0
infiniteLoopTest()
return true
}, true)
return Command.goto(loopCommands, 0)
}
}

文档生成时间:2025/7/7 12:07:06