Okay, I'll be very explicit. I ran this code:
DM = {{{0, 0}, {0, 0}}, {{0, 0}, {0, 0}}};
For[i1 = 1, i1 < 3, i1++,
For[i2 = 1, i2 < 3, i2++,
For[i3 = 1, i3 < 3, i3++,
If[i3 == 1, DM[[i1]][[i2]][[i3]] = A, DM[[i1]][[i2]][[i3]] = B]]]];
DM
The result was {{{A, B}, {A, B}}, {{A, B}, {A, B}}}
.
Then I ran this code:
DM = {{{0, 0}, {0, 0}}, {{0, 0}, {0, 0}}};
For[i1 = 1, i1 < 3, i1++,
For[i2 = 1, i2 < 3, i2++,
For[i3 = 1, i3 < 3, i3++,
If[i3 == 1, DM[[i1]][[i2]][[xx]] = A, DM[[i1]][[i2]][[xx]] = B]]]];
DM
The result was {{{0, 0}, {0, 0}}, {{0, 0}, {0, 0}}}
along with messages that xx is not a valid part specification.
I would be astonished if it mattered, but I'm running Mathematica 13.1.0.0 on a (non-silicon) MacBook Pro running Monterey 12.5.1
As for this
The nature of my mathematical problem is not relevant to this discussion
yes, I agree. Please don't send us the full domain description that you're working in. But surely you can describe the specific programming problem this code is intended to solve. Like, are you trying to create DM from scratch? If so, something like the ConstantArray suggestion from Sander would be better. Does DM come from some external source? Then it further depends on the semantics, but ReplacePart, MapIndexed, or even something like SubsetMap might be better. At the very least, the Do loop suggestion would be cleaner.
Of course, you may respond by reiterating that the
most obvious brute-force programming approach is (for me at this point) the simplest
and of course that is fine and natural. But why pick up a new language if you're not going to try to understand its strengths or at least become comfortable with its standard idioms? My hope is not just to help you get your code to work, my hope is that you'll learn better ways to program in Mathematica.