Thank you,
Probably the answer to my question is hidden around here, or even more in https://github.com/tensorflow/tensorflow/blob/5dcfc51118817f27fad5246812d83e5dccdc5f72/tensorflow/cc/ops/while_loop.cc, but not sure. What I would like to understand is the concept how to do it.
What I normally do when adding an Operational Node (and call it AddXXXX):

Create an elementary operation with TF_NewOperation
Set all inputs (TF_AddInput), inputlists (TF_AddInputList)
Set all attributes (e.g. TF_SetAttrBool)
Finalise it (TF_FinishOperation).

The problem is in TF_AddInput. It requires a TF_Output structure and that includes the existing operation that gives that output. In a linear Graph it is not a problem:

AddPlaceholder (name: PH)
AddSquare(input: PH, name: RES).
And then I can make a session and run it with one input tensor and use RES as output.

For a loop it should be something like:
AddPlaceholder(name: INP)
AddEnter(input: INP, name: ENT)
AddMerge(input: ENT, input : NEXT, name: MERGE)
[ make a COND output]
AddSwitch(input MERGE, input COND, name SWITCH)
AddExit(input SWITCH[true])
[ body using SWITCH[false] returning BODY ]
AddNextIteration(input: BODY, name: NEXT)
The problem is that AddMerge cannot be constructed as it would need NEXT as an input, but at that step NextIteration is not yet added. If I trick it with some dummy input, I cannot change it later to the output of NEXT.
I think the trick is somewhere around NextIterationName and CreateMerge (lines 55 and 66 in while_loop.cc), but I am lost.