Features of the mql5 language, subtleties and tricks - page 287
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
There is a variable X that can take the values 0, 1 and other values.
When X is 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
That's the only way I know:
There is a variable X that can take the values 0, 1 and other values.
When X is 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
That's the only way I know:
X = 1 - X;didn't realise it myself))
When X is equal to 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
Thank you)))
Thank you)))
Another option
switch(X) { case 0: X=1; break; case 1: X=0; break; default: break; }Another option
another
another
If we proceed from the task " how to make equal faster"...
Then we should reduce possible conventions and operations.
In my opinion switch will be the fastest at the level of assembly registers.
And the remainder from division is an expensive operation.
That's what Renat wrote.
another