That general pattern of looping over the data size was used to translate the original densities.
The condition is a metaprogram, so that gets evaluated statically. If the body of the loop is empty, the compiler should be able to easily optimize it away.
The bigger problem is that there are distributions like the normal where we do a bunch of additions where a multiplication would suffice if we reordered some of these. For instance, if sigma is a parameter but it’s a scalar and everything else is a vector of size N, then we should be able to use lp -= n * log(sigma) rather than doing lp -= log(sigma) inside a loop N times.