implement generateWhileCode