in reply to Re^2: returning to a loop later on
in thread returning to a loop later on

All your while loops are wrong. while tests the condition before entering the loop, but you want to execute the loop body once before checking whether to exit or not. Replace

while (...cond...) { ...body... }

with

do { ...body... } while (...cond...);