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

To add comments, please log in or register
helloea
97
helloea  


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?

Icham Aidibe
11600
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)

helloea
97
helloea  
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!

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

Hello, how should I understand?

lippmaje
875
lippmaje  
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") ?
Seng Joo Thio
1155
Seng Joo Thio  
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...

Icham Aidibe
11600
Icham Aidibe  
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.

helloea
97
helloea  
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?

Seng Joo Thio
1155
Seng Joo Thio  
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...
helloea
97
helloea  
Seng Joo Thio:

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

You have a lot of knowledge.

12
To add comments, please log in or register