Nested for loop php

So I'm creating this php local site for my work it is about mortgage and I made this code as a begging

<?php 
$income=1650;
$rate=7;
$period=240;
$graduation =60;
$paytoinc=40;
$rowage=7;
for ($l=1; $l <= $period ; $l++) { 
    for ($i=1; $i <= $graduation ; $i=+12) { 
        $NPV = (1/pow(1+($rate/100)/12, $i));
        $income = $income*(1+($rowage/100));
        $mpayment = $income *$paytoinc/100 ;
    }
    echo $mpayment = $income *$paytoinc/100 ;
}
?> 

I have 2 periods , 1 is included in the other for some reason this is making endless loop , I'm new so can anyone tell me what am I missing and doing wrong ?

Upvotes: 0

Views: 50

Answers (1)

Bart Friederichs
Bart Friederichs

Reputation: 33511

You are make a mistake here:

for ($i=1; $i <= $graduation ; $i=+12) { 

$i=+12 will assign 12 to $i. Change to:

for ($i=1; $i <= $graduation ; $i+=12) { 

That being said, learn how to debug. This bug would come up quite quickly if you echo'd $i in the innermost loop.

Upvotes: 4

Related Questions