How to control loop nesting in Perl 6?

This program was supposed to write triples of indices for which the sum is less than or equal to 7:

for ((1..7) X (1..7)) X (1..7) { .say if [+] $_ <= 7; } 

I thought it would only be a cycle above the top level of the list (and then the code will have an error in the body of the cycle, but thatโ€™s not the point), but it just goes through individual numbers, which upsets :( Is there a neat trick to avoid this? And BTW, is there a way to make an n-ary direct product?

+4
source share
1 answer

easiest way to name a link

 for (1..7) X (1..7) -> $a, $b { } 
+4
source

Source: https://habr.com/ru/post/1333131/


All Articles