I remember seeing some explanation from a English grammar book, written for people speaking another language, which basicaly said "when/while doing something" is just a shorthand of "when/while somebody is doing something", where "somebody is" must appear in the main clause, otherwise this shorthand usage is not valid. For example, it is wrong to say
“I watch TV, when sitting in my sofa.”
because in the main clause there is no "be".
This isn’t quite correct. It’s a bit better if the somebody appears in the main clause. The is doesn’t need to appear in the main clause at all.
Two examples:
An awesome sunset is a routine occurrence when chasing across the treeless Great Plains. (almost entirely ok)
This might sound a little bit odd to some people because the somebody (whoever is chasing) is completely missing from the main clause. But to a lot of people it will sound just fine. In ordinary speech, almost no one would notice.
One day, while looking through his grandparents’ attic, he found some old photographs. (definitely ok)
This one is impeccable. The implied subject of looking is the he of he found. Note that *“he was finding some old photographs” would be wrong.
Traditionally, while and when are called subordinating conjunctions. Some modern grammarians call them prepositions. Whatever you call them, they are followed by a clause: either an ordinary declarative clause (while Kaitlin worked on her paper), an -ing clause (while watching TV), a past-participial clause (when forced to respond), or a verbless clause (while in Rome, while an ice cream man in Hawaii, when drunk). Except in the first case, the subject of the dependent clause has to be figured out from context, and the verb be is implied.
When part is used without the article it has the meaning of section or segment - it is less than the whole object.
A part has the meaning of a specific sub unit. It normally isn't used for something which isn't an identifiable thing all by itself (though just to be confusing sometimes it is.)
Best Answer
Firstly: exercise is a noun
Secondly
Doing in this sense is a gerund. This means that doing is behaving as a verb within a noun phrase. So doing something with the body is effectively a noun that includes an action.
The sentence itself is acting as a definition for exercise, which is why the part after means is a noun.
To further clarify why using to to do is not natural, if you look at the accepted answer to the question you link to, then you can read this:
Since your sentence is a definition, it is actuality, therefore we use the gerund doing not the infinitive to do.