in reply to Finding Minimum Value

Initialize $mingrade before your loop to either something larger than the largest expected value, or the first value you encountered.

Hope that helps.