What is the difference between .. Return; , and Return(0); . ???? Help please

 

I cannot seem to get my head around the actual difference between Return; and Return(0);

I assume they each take me to a differnt point of the program.?

The book does not seem to make it clear for me.

Many thanks guys for all your help

 
theveeb:

I cannot seem to get my head around the actual difference between Return; and Return(0);

I assume they each take me to a differnt point of the program.?

The book does not seem to make it clear for me.

Many thanks guys for all your help

The function can return a value or not. Use "return(expression);" when you want your function to return value. Note that expression type must be same of function value type (or the cast operation must be possible).

So they both take you to the same point of the program: if called from the function start(), return terminates execution of the program till the next bar. If called from a custom function it will terminate that function and program will continue from the next operation after function call.


I think you have on your mind something like scripting in sh/ksh/bask, where you use exit - which returns exit code of the last command before exit or you can use:

exit 0 and then your script will terminate wit EC 0 (usually means - no errors).


If the function declaration was:

void myfunc( ...)

then you can use "return;".

Then in the program body (funciton start()) you call your function:

myfunc(...) ;


If you want your function to return a value, then declaration and body should be for example like this:

int myfunc()

{

if( condition() )

return(1);

else

retrun(0);

}


then you can call your function like this:

start()

{

int result;

result=myfunc();

if( result == 1 )

message("my_func_returned_1");

return;

}


There is ...:
"An example of how to use the operator 'return' that returns a value:"

at: https://book.mql4.com/operators/function


I hope that helps :)

Reason: