# Find the Largest Number in a List

### From HotDocs Wiki

Occasionally, you may need to find the largest number in a list of numbers. For example, if you have a repeated dialog in your template that gathers information about an individual's assets, you may want to find out which asset has the largest value.

You can use the following computations to find the largest answer for a repeated Number variable, or the largest number in a group of Number variables. The first computation begins by setting the result to the first answer for *Num Var*. Then, as the dialog is repeated, the computation result is compared to each answer for *Num Var*, and if a larger number is found, the result is set to the larger number. When the dialog reaches the last repetition, the result is the highest value.

The second computation uses the MAX expression to compare four separate Number variables. Following the order of operations, as indicated by the parentheses, the computation first compares *Num Var 3* with *Num Var 4* to find which number is larger. The result of that comparison is then compared with *Num Var 2*, and the maximum number from that comparison is then compared with *Num Var 1*. This final comparison then returns the largest of all four Number variables.

## Example

//Example 1: Find the largest value for a repeated Number variable. Num Var REPEAT Repeat Dialog IF Num Var > RESULT Num Var END IF END REPEAT //Example 2: Find the largest value of four Number variables. MAX( Num Var 1, MAX( Num Var 2, MAX( Num Var 3, Num Var 4 ) ) )

Num Var | A Number variable in a repeated dialog (Repeat Dialog). |

Repeat Dialog | Any repeated dialog containing a number variable (Num Var). |

Num Var 1 | A non-repeating Number variable. |

Num Var 2 | A non-repeating Number variable. |

Num Var 3 | A non-repeating Number variable. |

Num Var 4 | A non-repeating Number variable. |