# Iterative Calculation

Iterative calculations are supported by DsExcel. Along with that, you can specify the maximum number of iterations and maximum difference between the values of iterative formulas.

## Content

Iterative calculation is performed to repeatedly calculate a function until a specific numeric condition is met. DsExcel allows you to enable and perform iterative calculations by using **EnableIterativeCalculation** property of **IFormulaOptions** interface. Additionally, you can also set or retrieve the following:

* Maximum number of iterations by using **MaximumIterations** property
* Maximum difference between values of iterative formulas by using **MaximumChange** property

For example, if **MaximumIterations** is set to 10 and **MaximumChange** is set to 0.001, DsExcel will stop calculating either after 10 calculations, or when there is a difference of less than 0.001 between the results.
Refer to the following example code to perform iterative calculation in a worksheet by performing 10 iterations.

```csharp
//create a new workbook
Workbook workbook = new Workbook();

//enable iterative calculation
workbook.Options.Formulas.EnableIterativeCalculation = true;
workbook.Options.Formulas.MaximumIterations = 10;
var worksheet = workbook.Worksheets[0];
worksheet.Range["A1"].Formula = "=B1 + 1";
worksheet.Range["B1"].Formula = "=A1 + 1";

Console.WriteLine("A1:" + worksheet.Range["A1"].Value.ToString());
Console.WriteLine("B1:" + worksheet.Range["B1"].Value.ToString());

workbook.Save("IterativeCalculation.xlsx");
```