the RETURN operator

 

Hello friends,

I want to share with you my thoughts:

I can see different way of using the RETURN operator: 

I understand bool/double/int/string functions that returns a value.

BUT why void function uses RETURN or RETURN(0)? 

What it the diffidence? 

Thanks. 

 

You don't have to use return anywhere in a void function. Once the code is complete, it will 'return' by itself.

If you want the void function to end prematurely, then return is useful.

if(condition) { return; }

 

If you try to use return(0) on a void function, you should get an error or a warning (depending on whether #property strict is used)

Reason: