- difference between "return", "return(0)" & "return(-1)"
void function(){ ... return; } The function doesn't return anything. Print(function()) or int var = function() would not compile.
TYPE function(){ ... return(x); } The function returns a TYPE (int, double, string, datetime, or bool)
Print( "2+3=",Function(2,3) ); // Prints 2+3=5 int five = Function(2,3); : int Function(int a, int b){ return(a+b); }
- Lines 6-10 are not executed. The function returns to the caller. The caller of start is the terminal which then waits for the next tick (the returned value is ignored.)
what happens when "return" or "return(0)" or "return(-1)" is placed after line 5
If it stops, then, where is the position now (e.g. before line 1 or after line 10 or quits the question after line 5?)
what if this is not a function but int start() {......} - 2. above example, variable A has a "&" sign and B without a "&" sign, what is the difference with/without the "&" sign and how to use themThe ampersand is call by reference. The function can change the value of the variable
int x=1, y=2; function(x, y); Print("x=",x," y=",y); // Prints x=2, y=2 : void function(int& a, int b){ a++; b++; // a=2 and b=3 here. return; }
- Time to hit the books
- Lines 6-10 are not executed. The function returns to the caller. The caller of start is the terminal which then waits for the next tick (the returned value is ignored.)
Hi WHRoeder, thanks for your time
so do I understand correctly that if return (0) is placed after line 5 of int start(){..}, it ignores line 6-10 and waits for the next tick to start from line 1 again?
what about if it is return(-1) in this case?
int x=1, y=2; function(x, y); Print("x=",x," y=",y); // Prints x=2, y=2 : void function(int& a, int b){ a++; b++; // a=2 and b=3 here. return; }
- The ampersand is call by reference. The function can change the value of the variable
if this is the use of ampersand, then why not declare int x as global variable?
is it because if x is declared as global variable, it has a risk of being modified somewhere in the program whereas ampersand ensures only particular function(s) can modify x?
thanks again for your time.
int x; int init() { x=1; return(0);} int start() { int y=2; function(x, y); return(0); } void function(int a, int b){ a++; b++; return; }
if this is the use of ampersand, then why not declare int x as global variable?
is it because if x is declared as global variable, it has a risk of being modified somewhere in the program whereas ampersand ensures only particular function(s) can modify x?
thanks again for your time.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Below I have some basic questions while learning mql4.
Apologize if it is too remedial but I would really appreciate if anyone could help me to understand these questions or at least direct me to the right place, many thanks.
1. difference between "return", "return(0)" & "return(-1)"
for example, if I have a function (or start() ) with 10 lines like below
what happens when "return" or "return(0)" or "return(-1)" is placed after line 5
If it stops, then, where is the position now (e.g. before line 1 or after line 10 or quits the question after line 5?)
what if this is not a function but int start() {......}
2. above example, variable A has a "&" sign and B without a "&" sign, what is the difference with/without the "&" sign and how to use them
It would be great if anyone could explain above with a simple example.
with many thanks in advance.