<div dir="ltr">Hi all,<br><br>I'm a bit stuck with this so maybe someone can help me.<br><br>I'm writing a little program that needs to iterate through several nested 'for' loops. However, the number of loops (and therefore the depth of the nesting) cannot be predetermined.<br><br>I've read that lots of nested loops are bad form anyway, and that "you should do it with functions instead".<br><br>However I still can't work out how to set the number dynamically.<br><br><br><span style="font-family:monospace">for ((l=0; l<10; l++)); do<br><div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div> for ((m=0; m<10; m++))<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​;​</div> do<br>   <div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div>for (n=0; n<10; n++)); do<br>     <div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div>something<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ that uses l, m and n​</div><br>    done<br>  done<br>done</span><br><br>So this is what it needs to look like if nest_depth=3<br><br>But how do I write a program that iterates something<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ for nest_depth=4 (which in this case would use l, m, n and o)​, or any other number (which can't be predicted)?<br></div><br>cheers,<br>Doug<br><br>PS I didn't write this in Python just for speed, but feel free to reply in Python if you want - the practice would be good for me.<br></div>