Formula for edges of grid?

Are you asking about a simple loop or am I misunderstanding something severely?

272269-capture.png

This then, I think. You can get the rest of the edges, too. And it should be pretty scalable.