If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Actually, the outer loop will run first. On the first iteration of the outer loop, the inner loop will run, and keep running, until it terminates. Then, the next iteration of the outer loop will run, and on this iteration, the inner loop will run, and keep running, until it terminates. Then, the next iteration of the outer loop will run, ..., until the outer loop itself terminates. This applies whether the loops are for loops, while loops, or do while loops.

Originally Posted by Paul help!

1) do inner 'if' run before outer 'ifs'?

Likewise, the outer if statement will run before the inner if statement. It is simply a consequence of the flow of control proceeding statement by statement from the "top" to the "bottom" except where this flow is modified by control statements such as if statements and loops.

What is the use of loops within loops? Well, they are useful for expressing logic that involves some kind of iterations within iterations, but that's just another way for saying "loops within loops". Think of say, accessing arrays of arrays.

The most common example I've ever seen of a loop within a loop is when you want to parse data in a table or spreadsheet. The outer loop loops through all the rows and the inner one loops through all the cells in a particular row.

The most common example I've ever seen of a loop within a loop is when you want to parse data in a table or spreadsheet. The outer loop loops through all the rows and the inner one loops through all the cells in a particular row.

Great example.

"Sometimes, though, when you're a man, you get alone in your room with a computer and loop inside a loop. It's for fun...."

/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!