How can I return 2 different values when using if, else?

 
Hy guys, simple question and don't know what its wrong here. Please have a look:

   if( cond1 && cond2){                                                           
                 
            return 1;}                                                                                                      
         
      else if(cond3){
        
            return 0;}  

Warning: '}' - not all control paths return a value


Thanks for your support!

 
if( cond1 && cond2){ return 1; }
if(cond3){           return 2; }
// what are you returning here?
 
where is your "else"?
 
Sardion Maranatha #: where is your "else"?

None needed.

if() A; 
else B; 
C;

means do A or B then do C. If A is a return, break, or continue, there is no C in that case. Simplify to if() return; B; C.

If the B is a return, break, or continue, there is no C in that case. Simplify to if(not condition) return; A; C.

 
@William, thank you for always replying to my issues and helping me!

I just  would like to return integers, 1 and 0 and thats it. 
 
it goes like this:

int function1(int signal){

if(cond1 && cond2){
return 1;}

else if(cond3){
return 0;}
}
 
  1. Please edit your posts and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2. tradefy #: I just  would like to return integers, 1 and 0 and thats it. 
    int function1(int signal){
       if(cond1 && cond2){ return 1;}
       else if(cond3){     return 0;}
       // again what are you returning here?
    }
    
    Again, if your first if is false, there is no else (or else if) needed.
 
int function1(int signal){
   if(cond1 && cond2){ return 1;}
   if(cond3){          return 0;}
   // the return 1 is for buy signal and 0 for neutral
}
I would get an error if I use the above code:

'}' - not all control paths return a value

 
int function1(int signal){
   if(cond1 && cond2){ return 1;}
   if(cond3){          return 0;}
   
        return 99;
}

You need to have a return value outside the if statements in a function,
If non of the cond are true,  then the function need to return something,

 
tradefy:
Hy guys, simple question and don't know what its wrong here. Please have a look:

   if( cond1 && cond2){                                                           
                 
            return 1;}                                                                                                      
         
      else if(cond3){
        
            return 0;}  

Warning: '}' - not all control paths return a value


Thanks for your support!

This is very basic. The program needs a "default return value" incase neither (  cond1 && cond2 ) or  (cond3) are true. Update to:

int function1(){
   if(cond1 && cond2)return 1;
   if(cond3)         return 0;   
   else return -1; 
   // the return 1 is for buy signal , 0 for neutral and -1 is undefined
}

if neither of the conditions are true program returns -1 as default value. 

 
thank you guys, its clear to me now!
Reason: