The following lines of code counts how many rows a repeat with the field name 'Repeat_rpt' has.
This should be placed into the Form Script for the relevant form.
var count = Form.data.Repeat_rpt.length;
You can then use the count variable in conditions or to set values as you see fit.
Note that it is not necessary to have a field set to this value for document automation purposes. On submission of the form, each repeat's length is recorded in the submitted data. The format of the field that stores this piece of data is: Repeat Name + '_Count'. For the above example, you would use Repeat_rpt_Count in your template.
Alternatively, in a logic block, you would use the following:
var count = data.Repeat_rpt.length;