Validate multiple rows in subform

Validate multiple rows in subform

I currently have the following script in Form Actions > On Add > on validate:

for each  row in Order
{
inventoryamt = Promotional_Item_Input[ID = row.ItEm].Quantity_In_Stock;
if(Order.Quantity > inventoryamt.toLong())
{
rec = Promotional_Item_Input[ID = input.Order.ItEm];
alert "There are only " + inventoryamt + " left of " + rec.Item + ". Please adjust your order quantity.";
cancel submit;
}
}

It works to check the quantity of items ordered against quantity in stock for the first row in the subform, but it does not work for subsequent rows. Rows below the first one allows users to submit order quantities that are greater than our quantity in stock. Any advice to make this work for all rows in the subform?