How to creating N number of nested for loops

Srikrishna K :

can somebody please help me, to generate N number of nested for loops, it is simple simple if we know the N while we code, but if it is given by the user during the compile time then, how can we generate N number of for loops ?

TheoWckr :

The solution is mostly recursive function.
You can make a recursive function recFun(n : number) that take a value n and make n loops that are calling recFun(n-1) and stops at 1 or 0.

fun recFun(n : number)
   if(n == 0) return ??? ;
   else { 
       for(i = 0 ; i < n ; i++) 
           recFun(n-1);
   }

You can find example in C++ here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=397909&siteId=1