Couple of ways depending on what you are trying to do but the key is the same.
Inside my repeat I have a field that counts up some other field in my repeat.
I have a field the inherits the key from the Parent so I just count that.. Or just make a dummy field.
Field Calc
RecKey ${LineKey}
Then do a running total inside the repeat. Using once so that it grows as you add, and it does not recalc on me.
Then you can add a constraint right here to make sure they do not go to far. Note it does let them create 51 but they cannot save it. In one form I even set text to tell them right away they went too far.
Field Calc Constraint
PointNum once(count(${RecKey})) .<=50
If you want to make sure they went far enough then you need to move it outside the repeat. In my case I want them to do exactly 50.
Field Calc Constraint
PointsCompleted count(${RecKey}) .=50
I actually just do the last option since it will catch both. But technically they could then make like 100 and have to delete. But in our case that is not really an issue, they usually just miss one.
I hope that makes more sense, harder to type then I thought. But in the end you are just counting and then using a constraint.