Nested for loop problem

Can anyone tell me why these nested loops aren’t working? The inner loop seems to function properly but I get infinite rows out of the outer for loop… Thanks

[php]

<?php $columns = $_POST['columns']; $rows = $_POST['rows']; print ""; for($rcount = 0; $rcount <= $rows; $rcount++) { print ''; for($ccount = 0; $ccount <= $columns; $ccount++) { if($rcount = 0) { print ""; } else { print ""; } } print ''; } print '
$ccount$ccount
'; ?>

[/php]

what are you trying to accomplish? just trying to get a sepecific number of rows or columns?

Yes, right now I just want the rows and columns to match the rows and columns inputted in a form (It’s actually rows+1 and cols+1 because I want a heading along the top and on the left side). It will be a simple multiplication table.

I can’t figure out why I’m getting an infinite # of rows… I made the outer for loop exactly as I did the inner one. The inner one seems to be working (i.e. it prints the correct amount of columns)…

Ive got some code I can give you when I get home tonight. I did something similar for a project a few years ago

Thanks Richei - In an attempt to really strip it down to a bare minimum I took out the if statement I had in the inner loop… and now it is printing the table properly. Go figure.

I think it’s because I had = in the if statement, not ==

Probably, any comparison needs to use either == or === (identical), !=, or !=== (Not identical).

Sponsor our Newsletter | Privacy Policy | Terms of Service