That only helps if thereâ€™s autodiff inside the loop that is more efficient outside the loop. Loops themselves are very fast in Stan. That means this

```
real y[N];
for (n in 1:N)
y[n] ~ normal(mu, sigma);
```

is a lot slower than the vectorized form

```
y ~ normal(mu, sigma);
```

tghat doesntâ€™ carry over everywhere. For example,

```
real x[N];
real y[N] = exp(x);
```

isnâ€™t any faster than

```
real x[N];
real y[N];
for (n in 1:N)
y[n] = exp(x[n]);
```

because all the vectorized `exp`

function does is a loop down in C++ just like the loop code.

*Edit: Thereâ€™s no autodiff in transformed parameters or generated quantities, so there wonâ€™t be a speed difference between loops or vectorized operations for those functions. There still will be a big difference between matrix operations and loops. You definitely want to call matrix operations where possible because they have lots of optimizations built in.*