How to write If-else sequence in MQL4

 

Hello,


What is correct way to add if else statement.


Type 1 :


if (TradingAccountType == "Demo") 
    {
        UserTradeAccount = "Active";
    }
    else
    {
         if (TradingAccountNumber == "" && TradingAccountName == "")
          {
             UserTradeAccount = "Active";
          }
         else
         {
               if (TradingAccountNumber == TradingAccountNumberAuto || TradingAccountName == TradingAccountNameAuto)
               {
                     UserTradeAccount = "Active";
               }
         }
    }



Type 2 :


if (TradingAccountType == "Demo") 
    {
        UserTradeAccount = "Active";
    }
    else if (TradingAccountNumber == "" && TradingAccountName == "")
          {
             UserTradeAccount = "Active";
          }
         else if (TradingAccountNumber == TradingAccountNumberAuto || TradingAccountName == TradingAccountNameAuto)
               {
                     UserTradeAccount = "Active";
               }
         
    
 
anuj71:
if (TradingAccountType == "Demo")     {         UserTradeAccount = "Active";     }     else     {          if (TradingAccountNumber == "" && TradingAccountName == "")           {              UserTradeAccount = "Active";           }          else          {                if (TradingAccountNumber == TradingAccountNumberAuto || TradingAccountName == TradingAccountNameAuto)                {                      UserTradeAccount = "Active";                }          }     }
if (TradingAccountType == "Demo" || (TradingAccountNumber == "" && TradingAccountName == "") || (TradingAccountNumber == TradingAccountNumberAuto || TradingAccountName == TradingAccountNameAuto))
{
    UserTradeAccount = "Active";
}

this is what i recommend

 
anuj71: What is correct way to add if else statement.
if     (condition1){ doCondition1;}
else if(condition2){ doCondition2;}
⋮
else               { doConditionN[];}
 
Arpit T #:
this is what i recommend

Thanks for making it more simplified and reliable my existing if else logic. But my question is still same, how to write if else sequence in MQL4


If else sequence separately :


if (condition1) {
     //Condition 1 task
} else {
                if (condition2) {
                //condition2 task
                } else {
                        if(condition3) {
                        //condition3 task 
                        } else { //condition else task}


Else if statement sequence :

if (condition1) {
     //Condition 1 task
        } else if (condition2) {
                //condition2 task
                } else if(condition3) {
                        //condition3 task 
                        } else { //condition else task}