No loops needed with R's matrix indexing.
One test for whether a row,col number is the same diagonal is row+col being the same. You can also order the row and columns of a matrix by this principle, so use a two column matrix to deliver the values in the order:
M <- matrix(1:16, 4, 4)
idxs <- cbind( c(row(M)), c(col(M)) )
imat <- idxs[ order( rowSums(idxs), idxs[,1] ), ] # returns two columns
# turns out you don't need to sort by both rows and columns
# but could have used rev(col(M)) as secondary sort
> imat
[,1] [,2]
[1,] 1 1
[2,] 1 2
[3,] 2 1
[4,] 1 3
[5,] 2 2
[6,] 3 1
[7,] 1 4
[8,] 2 3
[9,] 3 2
[10,] 4 1
[11,] 2 4
[12,] 3 3
[13,] 4 2
[14,] 3 4
[15,] 4 3
[16,] 4 4
M[ imat ]
#[1] 1 5 2 9 6 3 13 10 7 4 14 11 8 15 12 16