Move while loops to extra package and adopt WhileCache from OMOP branch

Signed-off-by: Stefan Marr <git@stefan-marr.de>