# while into while

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi,

I need some help with multiple while loops.

I need to set a variable about the count of loops I want.

For example, \$i = 3; would do :

while(\$x[\$i-2] < 1) {
while(\$x[\$i-1] < 1) {
while(\$x[\$i] < 1) {
...
}
}
}

and \$i = 2 would do :

while(\$x[\$i-1] < 1) {
while(\$x[\$i] < 1) {
...
}
}

I can't find how to do it. I'm pretty sure I miss a small magic
trick....

If someone have an idea... Thanks

## Re: while into while

I have an idea that's probably beyond most procedural languages..as a
straight coding exercise BUT you MAY be able to do it as a recursive call

Consider the following

function loopy(\$i)
{
while (\$i && (something else))
{
}
\$i--;
if(\$i>0)
\$i=loopy(\$i);
return \$i;
}

That will exercise the same loop \$i times.

## Re: while into while

On Wed, 30 Nov 2011 06:36:00 -0800, monsieur madame wrote:

Recursive function, something like (untested):

function recurseWhile (\$x, \$i)
{
while(\$x[\$i-(\$i - 1)] < 1)
{
if (\$i != 0)
{
recurseWhile (\$x, \$i - 1)
}
else
{
...
}
}
}

Rgds

Denis McMahon