嵌套的while循环是否在golfscript中被破坏或者我不知道如何使用它们?
我想将 Q 从 5 迭代到 0,并且对于每次迭代,将 Z 从 10 迭代到 0。单个循环单独工作良好,并且它们似乎是自包含的(不依赖于操作之间的堆栈):
5:Q;
{"Q:"Q+ p Q}
{
Q 1- :Q;
}while
10:Z;{"Z:"Z+ p Z}{Z 1- :Z;}while
Output:
"Q:5"
"Q:4"
"Q:3"
"Q:2"
"Q:1"
"Q:0"
"Z:10"
"Z:9"
"Z:8"
"Z:7"
"Z:6"
"Z:5"
"Z:4"
"Z:3"
"Z:2"
"Z:1"
"Z:0"
但是如果我把 Z 循环放在 Q 循环中,我会得到奇怪的结果:
5:Q;
{"Q:"Q+ p Q}
{
10:Z;{"Z:"Z+ p Z}{Z 1- :Z;}while
Q 1- :Q;
}while
Output:
"Q:5"
"Z:10"
"Z:9"
"Z:8"
"Z:7"
"Z:6"
"Z:5"
"Z:4"
"Z:3"
"Z:2"
"Z:1"
"Z:0"
"Z:0"
基于 Z 打印两次,似乎只有一个当前条件块,并且“while”的任何执行都会覆盖它。
无论如何,我将如何在 Golfscript 中完成这一壮举?