Filling sub and super diagonals of a matrix

I am working on implementing a model which uses a precision matrix specification for a multivariate normal model. In this model the precision matrix is tridiagonal. In R, I use the following code to generate the precision matrix once I have calculated the diagonals.

  diag(prec)[par_seq_1]<-prec_diag
  diag(prec[,-1])<-prec_sdiag
  diag(prec[-1,])<-prec_sdiag

Is there an equivalent function to replicate this in stan? I’ve looked at the diagonal matrix functions and slicing but wasn’t sure if there is a similar functionality.
If not, would it be best to implement this with a loop?

Neat, I’d never seen this construct before. I’d do:

matrix[N,N] prec = diag_matrix( prec_diag ) ;
prec[2:N,1:(N-1)] = prec_sdiag ;
prec[1:(N-1),2:N] = prec_sdiag ;

But note that that leaves the remaining elements as zeroes; how are you filling those in R?