Then you can use iterate with CartesianIndices(A):
julia> I = CartesianIndices(A)
CartesianIndices((5, 5))
julia> iterate(I, CartesianIndex(4,1))
(CartesianIndex(5, 1), CartesianIndex(5, 1))
julia> iterate(I, CartesianIndex(5,4))
(CartesianIndex(1, 5), CartesianIndex(1, 5))
julia> iterate(I, CartesianIndex(4,5))
(CartesianIndex(5, 5), CartesianIndex(5, 5))
julia> iterate(I, CartesianIndex(5,5)) # last index, returns nothing
(When it doesn’t return nothing, it returns the same index twice due to the iterate API, but you can just ignore the second return value and the compiler should eliminate it.)