在Perl中,有一种打破外部循环的能力,如下所示:
AAA: for my $stuff (@otherstuff) {
for my $foo (@bar) {
last AAA if (somethingbad());
}
}
(语法可能错误),它使用循环标签从内部循环中断开外部循环.Ruby中有类似的东西吗?
在Perl中,有一种打破外部循环的能力,如下所示:
AAA: for my $stuff (@otherstuff) {
for my $foo (@bar) {
last AAA if (somethingbad());
}
}
(语法可能错误),它使用循环标签从内部循环中断开外部循环.Ruby中有类似的东西吗?
您需要的是非本地控制流,Ruby有几个选项:
throw
/catch
Continuations
赞成的意见:
GOTO
个更好的孪生子.欺骗:
Exceptions
赞成的意见:
欺骗:
100/101
这(大致)就是它的样子:
catch :aaa do
stuff.each do |otherstuff|
foo.each do |bar|
throw :aaa if somethingbad
end
end
end
赞成的意见:
StopIteration
异常来终止.欺骗: