The function does not work in ESP8266

That is exactly what the return does. What is so special about the code reaching the closing brace of loop() ?