开发者

How to control nestedness of loops in Perl 6?

开发者 https://www.devze.com 2023-02-01 02:20 出处:网络
This program should\'ve written triples of indices that have a sum less or eq开发者_运维百科ual to 7:

This program should've written triples of indices that have a sum less or eq开发者_运维百科ual 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?


the easiest way to to name the reference

for (1..7) X (1..7) -> $a, $b { }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号