Ulrich Drepper's 'What Every Programmer Should Know About Memory' opens with exactly this example because it's the single cheapest performance win in C: matching loop order to memory layout costs nothing but a rewrite. Numerical libraries like BLAS and the Linux kernel's own hot paths are obsessive about this, since a naive column-major sweep on a large matrix can be 100x slower for identical arithmetic.