# 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 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.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 [setEnableIterativeCalculation](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IFormulaOptions.html#setEnableIterativeCalculation) method of [IFormulaOptions](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IFormulaOptions.html) interface. Additionally, you can also set or retrieve the following:

*   Maximum number of iterations by using [setMaximumIterations](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IFormulaOptions.html#setMaximumIterations) method
*   Maximum difference between values of iterative formulas by using [setMaximumChange](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IFormulaOptions.html#setMaximumChange) method

For example, if **setMaximumIterations** is set to 10 and **setMaximumChange** 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.

```Java
// Create a new workbook
Workbook workbook = new Workbook();

// Enable iterative calculation
workbook.getOptions().getFormulas().setEnableIterativeCalculation(true);
workbook.getOptions().getFormulas().setMaximumIterations(10);
IWorksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getRange("A1").setFormula("=B1 + 1");
worksheet.getRange("B1").setFormula("=A1 + 1");

System.out.println("A1:" + worksheet.getRange("A1").getValue().toString());
System.out.println("B1:" + worksheet.getRange("B1").getValue().toString());
    
// Save to an excel file
workbook.save("IterativeCalculation.xlsx");
```