Skip to main content

break 跳出循环(支持嵌套遍历)

break

类型: MethodDeclaration

所属类: CommandFunctionList

定义位置: command.ts

描述

跳出循环(支持嵌套遍历)

返回值

类型: CommandFunction \| null

源代码

位置: 第 3116 行

protected break(): CommandFunction | null {
const {stack} = this
let i = stack.length
while (--i >= 0) {
if (stack[i].loop) {
// 找到最近的循环所在的上一层编译上下文
const {commands, index} = stack[i - 1]
const jump = Command.goto(commands, index + 1)
// 生成运行时函数:先弹出 forEach 迭代器,再跳转
return () => {
const fe = CurrentEvent.forEach
if (fe && fe.length > 0) {
fe.shift() // 移除当前(最内层)迭代器上下文
}
return jump()
}
}
}
return null
}

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