How can I make nested loops in PARI / GP that span multiple lines at each level? I often have to do several things inside loops, and for readability, I don't like to write my loops on one line. For a loop over a single variable, I did this:
for(i=1,10,{ printf("%u\n",i); })
However, for nested loops, I only managed to split the lines at the same level. It works:
for(i=1, 10, for(j=1, 10, { printf("%2u\t%2u\n", i, j); }));
This also works:
for(i=1, 10, { for(j=1, 10, printf("%2u\t%2u\n", i, j)); });
However, this is what I really would like to do:
for(i=1, 10, { for(j=1, 10, { printf("%2u\t%2u\n", i, j); }); });
This last example does not work; he gives an error:
*** sorry, embedded braces (in parser) is not yet implemented. ... skipping file 'nested_for.gp' *** at top-level: printf("%2u\t%2u\n", *** ^-------------------- *** printf: not a t_INT in integer format conversion: i. *** Break loop: type 'break' to go back to GP
I am using PARI / GP 2.5.3 for OS X 10.8.3. I write my scripts to the nested_for.gp file and run them with gp ./nested_for.gp in Bash.