You're probably looking for an API defined way to accomplish this, and I'm not certain there is one. Therefore, there shouldn't be anything wrong with using a standard control statement, ie: for loop. Soo...
1) for all elements up to and including 100
// ..... do something...
// if attempt to add past 100
// throw exception(which is kinda of pointless since that's what the control
// statement was for - only elements up to an including 100)