The function does not work in ESP8266

I agree with @MicroBahner. Using return as quick 'n dirty escape from the rest of loop() is not good code structure. Not as bad as using goto, but not good.

Instead, use if/else to skip the remaining code in loop().

I try to use return only in non-void functions, and even then, have only one return statement where the result is returned to the caller.