Assign material to face

I have an object that I want to assign materials to particular faces by using an if then statement.

Something like
if material = "White" then
assign Autodesk Wall Paint/Glossy Ivory Gloss material to $.EditablePoly.SetSelection #Face #{15..16}
else if... and so on.

Even a script to assign a material to the face selection would be great.