coldfusion loop variable increment value

3.8k views Asked by At

I'm working on outputting a graduated payment schedule that increases every 24 months. I'm having some trouble getting the payment value to increment correctly so that payment 2 is the total of the initial payment times the increment. Then, payment 3 is a total of payment 2 times the increment. For example, the first couple of payments should look like this...

Payment 1: $274.22 increase payment $13.64
Payment 2: $287.86 increase payment $15.03
Payment 3: $302.18 increase payment $15.78
Payment 4: $317.22 increase payment $16.57

and so on... The increment is .04975. The initial payment times the increment + the original payment amount becomes the payment 2. Then, the second payment times the increment + payment 2 becomes the third payment. The third payment times the increment + the third payment becomes payment 4, etc...

I was working with a loop, like this...

<cfset loopterm = 360 />
<cfset incr = .04975 />
<cfset gradinital = 274.22 />

<cfloop from="1" to="#( loopterm / 24 )#" index="i">
   <cfset newamt = newamt + ( gradinitial * incr ) />
   <cfoutput>
      #dollarformat( newamt )#
   </cfoutput>
</cfloop>

Problem is the increase is always the same amount and does not graduate.

Thank you for any help you can provide.

1

There are 1 answers

4
Avery Martell On BEST ANSWER

I think you're close, but you're using the same gradinitial value in every calculation, so your increase value is always the same.

<cfset loopterm = 360>
<cfset incr = .04975>
<cfset newamt = 274.22>

<cfloop from="1" to="#( loopterm / 24 )#" index="i">
  <cfoutput>
    #dollarformat(newamt)#<br />
  </cfoutput>
  <cfset newamt = newamt + ( newamt * incr ) />
</cfloop>

This produces a result set like this:

$274.22
$287.86
$302.18
$317.22
$333.00
$349.57
$366.96
$385.21
$404.38
$424.49
$445.61
$467.78
$491.05
$515.48
$541.13

It's not perfect, but hopefully that gets you on the right track.