Condition is just loop until reaching the predefined iteration number. Apart from that it seems that you did what I thought was right:
x = f(x_old)
old_x = x

The idea is to get the network’s output, compute some loss function on it, backprop into the network and then take this output as the network’s input in the next iteration. Does this make sense?