The mentioned Overpass API uses sets as a sort of fundamental concept, so the code
way[building][!name];foreach{(._;>;);out;}
can be replaced with
way[building][!name];(._;>;);out;
The "(._;>;);" stanza is sort of dense and seems opaque without knowing what it's doing, but it's straightforward, returning the union "();" of the previous result "._;" and the children of the previous result ">;".
The change I propose above adjusts the ">;" to operate on all of the "way[building][!name];" results together, rather than each element one at the time.
It doesn't do exactly the same thing, it inserts the lat/long into the parent instead of returning the nodes. Often doesn't matter, but it does if you are using a library that is expecting osm xml.
The change I propose above adjusts the ">;" to operate on all of the "way[building][!name];" results together, rather than each element one at the time.