我试图找出一种处理动态嵌套循环级别的简单方法.考虑以下函数,它接受2个参数:#num of loops和max value.
void PrintLoop(int maxloop, int maxvalue)
PrintLoop(1,2);
// output
0
1
PrintLoop(2,2);
// output
0, 0
0, 1
1, 0
1, 1
PrintLoop(3,2);
// output
0, 0, 0
0, 0, 1
0, 1, 0
0, 1, 1
1, 0, 0
1, 0, 1
1, 1, 0
1, 1, 1
Run Code Online (Sandbox Code Playgroud)
等等...
有没有办法编写一个可以生成这种"动态嵌套循环"行为的函数?
谢谢你的帮助