In each iteration of the “while loop” the algorithm picks two disconnected
nodes v and w, of degree k and l correspondingly, for which
joint_degrees[k][l] has not reached its target yet. It then adds
edge (v, w) and increases the number of edges in graph G by one.

The intelligence of the algorithm lies in the fact that it is always
possible to add an edge between such disconnected nodes v and w,
even if one or both nodes do not have free stubs. That is made possible by
executing a “neighbor switch”, an edge rewiring move that releases
a free stub while keeping the joint degree of G the same.

The algorithm continues for E (number of edges) iterations of
the “while loop”, at the which point all entries of the given
joint_degrees[k][l] have reached their target values and the
construction is complete.