I would like to show all the values of this loop in the tableview. The code is to calculate an Amortization Table for loans. I tried saving the data of the loop in the array, but it always gives me the last values. I really got stuck on this. So how can I do that, please? This is my code:

```
import UIKit

class tableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet var tableView: UITableView!

var arr = [Int]()
var cell:tableCell!
var TPayment: float_t! // calls value of 59600 from main controller
var years1: float_t! // number of months = 180 ( 15 years)
var monthlyPayment: float_t! // 471
var interest: float_t! // 5%
var principil: float_t! //222
var interestrate: float_t! // 249
var initil: float_t!
var data = Array<float_t>()
var data2: NSMutableArray = []

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self

    tableView.dataSource = self

    let c = Int(years1)
    arr += 0...c

    tableCalculation()

        // Register custom cell
        let nib = UINib(nibName: "table", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "cell")
}

func tableCalculation() {
    let years = Int(years1)
    initil = TPayment - 0

    for i in 0..<years {
            initil = initil - principil
            interest = initil * interestrate                
            principil = monthlyPayment - interest                
            print("Month : \(monthlyPayment),   principil: \(principil),interest: \(interest), initi: \(initil)")
            data = [interest]
            self.data2 = [initil]
    }        
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return arr.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell     {

    cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! tableCell
    cell.lbl1.text = "\(arr[indexPath.row])"        
    cell.lbl2.text =  "\(monthlyPayment)"
    cell.lbl3.text = "\(data[indexPath.row % data.count])"
    cell.lbl4.text = "\(principal)"
    cell.lbl5.text = "\(self.data2[indexPath.section])"        
    return cell        
}    

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("Row \(indexPath.row) selected")
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 40
}
}

```

[Table View with UITableView](http://i.stack.imgur.com/WoYiv.png)

[Table view with print()](http://i.stack.imgur.com/VcOLE.png)