如何控制 Perl 6 中循环的嵌套?
这个程序应该编写总和小于或等于 7 的索引三元组:
for ((1..7) X (1..7)) X (1..7) {
.say if [+] $_ <= 7;
}
我认为它只会在列表的顶层循环(然后代码会在循环体中出现错误,但这不是点),但它只是循环遍历单个数字,这令人沮丧:( 有一个巧妙的技巧来避免它吗?顺便说一句,有没有办法制作 n 元直接乘积?
This program should've written triples of indices that have a sum less or equal to 7:
for ((1..7) X (1..7)) X (1..7) {
.say if [+] $_ <= 7;
}
I thought it would only loop over the top level of the list (and the code would have an error in the loop body then, but it's not the point), but it just loops over individual numbers, which is frustrating :( Is there a neat trick to avoid it? And BTW, is there a way to make an n-ary direct product?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命名参考的最简单方法
the easiest way to to name the reference