a bool type variable is true or false . . . there is no point in saying if true == true or if true == false . . .
! is NOT, so NOT true is the same as false
int = integers 1-2-3-etc, bool = true or false, if( !something ) means if( something==false ). The ! command only works on bool type variables. It's used as a form of short hand way of doing things. Similarly if( something ) means if( something==true ). Again the short hand only works for bool type variables.
We understand that any statement can be either true of false, including this statement. So in maths 1+1=2 is a true statement and 1+1=5 is a false statement.
In life people make conected statements with either the words AND and OR.
In life people say 'That fact is NOT true' so logically the statement about the 'fact' is false. If Exclamation mark is defined to represent the word NOT then we could write the previous sentences in shorthand as !fact=false.
The function IF takes two entities and compares them (comparing could be simplly done by subtracting one from the other and seeing if the result is zero or other than zero) and then 'jumps' to code that deals with the result of truth or falsness.
Now we need to define our number system because numbers come as whole numbers or whole numbers with a part choped off. The number 3 is a whole number and in a whole number system you can not add 0.5 unless you CHANGE 3 to 3.0.
This may seem strange if you ae not familiar with the way computers handle numbers.
Finally the idea of something. This is the same as when learning algerbra 5+X=7 what is the value of X. Here X by the nature of the equation is 2 but X is not always this value for in further questioning about sums e.g 2+X=7 what is the value of X? the value of X has changed. So X can be diferent values so X is VARIABLE or somevalue or something and you could picture a closed box with the word something on it. We don't need to know whats in the box until we use it like in an If function.
The function IF takes two entities and compares them
No.
If takes exactly only *ONE* argument (and one or more blocks of code). This one argument can either be an expression that evaluates to True or False, for example an expression like (a==b), or it can be (as shown in the original question) just be a variable that contains True or False. Variables that contain such truth values are called Boolean variables (named after George Boole https://en.wikipedia.org/wiki/George_Boole) and in mql4 the name of this data type is bool. In other languages like Pascal for example this data type is called Boolean.
Sometimes in some languages also other types like for example Integer (int) can be (ab)used to be passed into an if or while construct as if they were boolean values but this only exploits the fact that some languages will silently cast 0 into False and any other value into True. A sane compiler with proper type checking (like Pascal for example) will refuse to compile such sloppy code and demand explicit Typecasting and [Off-Topic]: I wish all beginning C programmers would first be forced to learn programming in Pascal at least for 2 years before they are allowed to touch C or C++ (if they then still want any of the C languages after the 2 years, which I seriously doubt).
And btw, if is not a function, its a control structure since it controls the flow of the program, the control flow, (other control structures are while, for, and switch). I know, I sound like a bean counter here but after using a compiler that is as pedantic as the Pascal compiler for more than 20 years almost exclusively I have inevitably learned how to count beans.
if(your knowledge is > than my post)
{
then you understand coding;
}else{
you don't know much about coding;
}
if(your knowledge is > than my post)
{
then you understand coding;
}else{
you don't know much about coding;
}
XD
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hey guys i jsut have two questions which i cant answer myself by googling or with the book:
what does this mean?:
int/bool something
if (!something)
what does the "!" tell me and why is there no condition in the ()?
and the second question is:
its almost the same as top what does it mean when there is simply no condition in the ()?:
in/bool something
if(somethin)
thanks in advance.