Is there a difference between "if" and "&&"?

 


double

 MathematicalAchievement = 

90

 ; 


double

 ScoreOfChinese = 

80

 ; 


void  

OnStart

()


  { 
   

if

(MathematicalAchievement> 

90

 && ScoreOfChinese> 

90

)


     { 
      

Print

“VeryGood”

); 


     } 


  }


double

 MathematicalAchievement = 

90

 ; 


double

 ScoreOfChinese = 

80

 ; 


void  

OnStart

()


  { 
   

if

(MathematicalAchievement> 

90

)


     { 
     

if

(ScoreOfChinese> 

90

)


     { 
      

Print

“VeryGood”

); 


      } 


     } 


  }

Are these two expressions the same?

 

In the first one, you are using 2 conditions (Mathematical&&Scoreofchinese) with ONE "if" statement. 

In the second one, you're first looking to confirm a first condition (Mathematical) in a if statetement, before confirming the second one (Scoreofchinese) with a second statement. 

Same result. You would choose one over the other depending on your need. Be sure to read also about the "||" (OR)

 
Icham Aidibe:

In the first one, you are using 2 conditions (Mathematical&&Scoreofchinese) with ONE "if" statement. 

In the second one, you're first looking to confirm a first condition (Mathematical) in a if statetement, before confirming the second one (Scoreofchinese) with a second statement. 

Same result. You would choose one over the other depending on your need. Be sure to read also about the "||" (OR)

wow!Programming is really detail-oriented work!If you don't say it, I can't understand it!

 
Same since Build 600 and Higher. 2014.02.03
 
William Roeder:
Same since Build 600 and Higher. 20 14.02.03

Hello, how should I understand?

 
William Roeder:
Same since Build 600 and Higher. 2014.02.03
How was if(a) if(b) Print("true") ever different from if(a&&b) Print("true") ?
 
lippmaje:
How was if(a) if(b) Print("true") ever different from if(a&&b) Print("true") ?

Before Build 600, both 'a' and 'b' are evaluated in 'if(a&&b)' regardless of 'a' being true or false - so if you have 'if(a>0 && b/a>4)', you'll crash when 'a'==0...

 
helloea:

wow!Programming is really detail-oriented work!If you don't say it, I can't understand it!

Sure you would have understand after few experimentation.

 
Seng Joo Thio:

Before Build 600, both 'a' and 'b' are evaluated in 'if(a&&b)' regardless of 'a' being true or false - so if you have 'if(a>0 && b/a>4)', you'll crash when 'a'==0...

Did you know that from reading the documentation?An experiment?Or somewhere else?

 
helloea:

Did you know that from reading the documentation?An experiment?Or somewhere else?

From here: https://docs.mql4.com/mql4changes

What's New in MQL4
What's New in MQL4
  • docs.mql4.com
Starting from build 600, MQL4 programming language has been completely revised reaching the level of MQL5 - now you can develop trading robots in MQL4/5 using the unified MetaEditor development environment, single style, libraries and debugging tools. MQL4 is popular among automated system developers due to the ease of learning and a huge...
 
Seng Joo Thio:

From here: https://docs.mql4.com/mql4changes

You have a lot of knowledge.

Reason: