【发布时间】:2019-04-19 15:54:29
【问题描述】:
我正在尝试使用 2 个排序海龟列表打破嵌套的 foreach 循环。 但是,netlogo 不仅离开了内部循环,还打破了整个过程。 我有一个类似下面的代码(这个是编造的,但结构完全相同):
to do-something
let xturtles sort-by [ [a b] -> [birthday] of a > [birthday] of b ] turtles
;; construct an ordered set
foreach xturtles [ the-xturtle ->
ask the-xturtle [
let xage birthday
let yturtles sort-by [ [a b] -> [birthday] of a > [birthday] of b ] turtles with [birthday < xage]
;; construct a second ordered set
foreach yturtles [ the-yturtle ->
let breakout-condition? false
ask the-yturtle [
if (hidden? ) [
set breakout-condition? true
]
]
if breakout-condition? [ stop ]
]
]
]
end
但是,当达到停止条件时,netlogo 会跳出整个过程,而不是继续外部循环(xturtles 循环)?
这是预期的行为吗?如果是这样,在这种情况下有什么好的做法?
谢谢! 费利克斯
【问题讨论】: