As you know, while loops will execute as long as a condition is true. The first one says while you can assign $row from mysql_fetch_assoc it can continue. When an array reaches its end you will not be able to assign it, making the while loop end. Mysql_fetch_assoc returns an array, so you can apply foreach to $row.
The syntax of foreach is
foreach($arr as $key => $value)