Rewrite deprecated control to loop statements