[MQL4 Coding Help] How to write If-else sequence in MQL4

shanmugapradeep

Corporal
Messages
88
Hello,

What is correct way to add if else statement.

Type 1 :

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

Type 2 :

Code:
if (TradingAccountType == "Demo")
{
UserTradeAccount = "Active";
}
else if (TradingAccountNumber == "" && TradingAccountName == "")
{
UserTradeAccount = "Active";
}
else if (TradingAccountNumber == TradingAccountNumberAuto || TradingAccountName == TradingAccountNameAuto)
{
UserTradeAccount = "Active";
}
 
Both Type 1 and Type 2 are correct ways to add if-else statements, and they achieve the same result in your code
 
Back
Top