Table: foreach TR - synchronous

Table: foreach TR - synchronous

Hello,

As you can see in attachment, I have an original table which should be manipulated by jquery.
I worry that I cannot find a way to run a for-loop synchronously instead of $("...").each(function... which is asynchronous :-(

What I want to do:
If there are <td><span>s in the 2nd column that are empty, then the upper TD with a non-empty span might have a rowspan to "overlap" the empty ones. It's a bit odd to describe, but the attached HTML shows easily what I am trying to explain...

With a for-loop which runs reversly from the last to the top, this might be possible. Is there a better or easier way to do so?


Replacing the table by a nested list may be an alternative, but please let me know how to solve it with the table as given.

Thanks a lot!