How do you get the boundary indices of grid?

I know you can use modulo %10 to get one side of a grid, how would I get the other 3 using math without having to specify each target index.

So using math, how would I get the indices of the outer grid?

This is my working solution so far.

My current limitations are having to use grid sizes with a 5x5 base

https://i.imgur.com/3CICpJs.png

Is is easiest to work it out during spawning?

I have two loops:

and they spawn a cube:

Then you can figure out where the edge is:

320919-screenshot-5.jpg

Wow thanks for this!