As such home-truths are being given (I'm sure this is on the Wiki, and numerous times on the forum, but I don't think it hurts to repeat it where new people can pick up on it even before they know that they'd like to know), it's also useful to note that putting a wall construction where you don't want them to stand (that doesn't stop them from standing anywhere, of course) is also a good way of guiding your dumb little dwarfs to a safer, more logical and generally less awkward and frustrating set of construction practices.
Happy place
####### ####### Existing wall
^--gap!!!
Sad Place
Set to build the wall ("O") in the gap you want to fill and it's random[1], but set another one up ("S") and Suspend it, thus:
Happy place
#######O####### Existing wall
S
Sad Place
...and the Dwarf will build that "O" wall segment from the top. After which, you can cancel the "S" wall altogether.
But the diagonal-build gap is also useful in other circumstances.
Imaging you're getting a drain set up (E-W in the following diagram) and find some interesting ore slicing across your path. You want to dig it all out.
#$$$##
####...######
+++++...+++++
######...####
##$$$#
After digging out the 'lining' wall, you could re-wall and then try to approach the ore on a separate trip (so that the water can flow immediately, but you can still get what you want out of the ground)
vvv later approach from this direction
#$$$##
####OOO######
+++++...+++++
######OOO####
##$$$#
^^^ and this one
or if you have spare time (or must, because you'll never be able to dig around the outside, for one reason or other) you could continue to mine (and expedite the ore removal by whatever means you prefer)
##...##
##...##
####...######
+++++...+++++
######...####
##...##
##...##
But if you don't then want your ore-drift filled with water, but can't yet get access or egress from the vein-side part, do the following:
##...##
##...##
####OO.######
+++++...+++++
######.OO####
##...##
##...##
In fact, you can do this even while they're still extracting the ore spoil and/or wandering in and out on other preparatory work. Then, when you're happy (or you absolutely must move on), the final wall block will, by the OP's mentioned diagonality rule, be filled in safely without any trapping going on.
[1] Actually, it isn't, as they'd normally build from the North anyway, or West when it comes to East-West gaps being filled. Which if you can remember this is another way of ensuring you're not trapped. But the diagrams are just for demonstration purposes. Flip/rotate the way you're applying the method and the Happy/Sad separation would still work just fine, even when its impossible to approach the problem from a North/West-biased standpoint.)