How to order the way in which objects are rendered?

     Let's say for example I have an Int called "Layer" in all the objects that I have. Multiple objects can have this Int set to the same amount , and the layer int can go as high as 999. I want all the objects with the Layer Int equal to 1 drawn first and so on. I know I can easily do this if I had 3 layers with just 3 if statements, but how would I handle numbers such as 999 different "Layers?" ?