Caches are not often taught at first because it is something that is implemented by the hardware and the details will quickly get very technical. Programmes also don't really have any control over caches and they are something that pretty much work under the hoods optimizing memory access automatically. On most beginner level stuff the performance difference isn't usually noticeable either but in heavy calculations where a lot of data is processed, the difference between good and bad cache optimization can make a huge difference.
In your case from what I gathered, you have some sort of 3d structure where the data is stored in a list something like this 000, 100, 200, 010, 110, 210, 020, 120, 220, 001, 101, ... where the numbers mean the x, y and z coordinates (3x3x3 in this case). If you made three for loops like this:
for z from 0 to 2
for y from 0 to 2
for x from 0 to 2
Access xyz here
```You would get the values in same order as they are in the list above. Instead if you did:
```py
for x from 0 to 2
for y from 0 to 2
for z from 0 to 2
Access xyz here
```You would access values in order `000, 001, 002, 010, 011, ...` which would be all around the list probably causing a lot of cache misses which as discussed above can be bad for performance. Depends on many factors starting from the hardware ending on your implementation on how much that matters but in cases like this, fixing the issue is as easy as nesting the for loops in correct order (assuing that doesn't break something else).