Essentially, the number of iterations in the inner loop can decrease by one every time, as show in the code below. It detects impedance changes at the probe. If the probe is placed in a conductive medium, the output voltage increases. IC23 buffers the sine wave and IC22 rectifies the signal. The transformer and R58 form an impedance divider.
Impedance changes in the secondary also show up as impedance changes in the primary.
This circuit also provides galvanic isolation between the electronics and the medium under test. When building a structural object, like a bridge, the fasteners, like bolts, are usually chosen to be of a material that is slightly more anodic than the structural materials. Anodic materials will corrode due to galvanic action. Fasteners are replaceable on a preventative maintenance schedule. If structural members corrode, maintenance becomes very expensive.