Download MetaTrader 5
To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
Keep Marcos
120
Keep Marcos 2016.02.17 23:33 

Hello people!!

Why some programmers put the "!" before a function ??

example:

!isPositionOpen() and isPositionOpen()

What do the different "!" ??

 

thanks for help! =]

developer787
4
developer787 2016.02.18 01:05  
bool SampleFunction()
{
    return(true);
}

// The "!" operator is used to negate the value of a function. If a function returns "true", it will make it "false" and vice-versa.
// Example

if(SampleFunction() == true)
{
    Alert("TRUE");
} else {
    Alert("FALSE");
}
// Alerts "TRUE".

if(!SampleFunction() == true)
{
    Alert("TRUE");
} else {
    Alert("FALSE");
}
// Alerts "False".


whroeder1
13610
whroeder1 2016.02.18 01:36  
KeepMarcos: Why some programmers put the "!" before a function ??
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
developer787
4
developer787 2016.02.18 18:44  
WHRoeder:
KeepMarcos: Why some programmers put the "!" before a function ??
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
Since the OP did not know what the "!" meant, I used the example above to make the point extra clear and obvious, however, your clarification is correct. Hopefully the OP now understands what the "!" operator does and is not further confused by your clarification which does not answer OP's question. Cheers
/
To add comments, please log in or register