simplified while loop compilation with fallback to function call