What does question mark mean in mt5 code

 

I have seen this code in the source of an indicator and just wondering what does the question mark ? accomplish and conjunction with the colon : .


val[i] = (absValue > 0) ? workTrend[i][_TDF]/absValue : 0;
         levup[i] = TriggerUp;
         levdn[i] = TriggerDown;
         valc[i]  = (val[i] > levup[i]) ? 2 : (val[i] < levdn[i]) ? 1 : 0;
 
Peter Williams: I have seen this code in the source of an indicator and just wondering what does the question mark ? accomplish and conjunction with the colon : .
Ternary operator.

if the expression in front of the ? Is true, use expression after ?.

If it is false, use expression after :.
 

When in doubt, consult the documentation — Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:

Easier than that is selecting the section in MetaEditor and pressing F1, and it will show the context sensitive help.

 

Thanks to you both.  I had trying search and found nothing - hence my question.

Fernando - I guess if I knew  this was a Ternary operator or what a Ternary operator was then I would have found the documentation.

The search engine on this website isn't the best - didn't return anything meaningful for question mark.

Have now followed link to full explanation.


Thanks again to Dominik & Fernando

 
Peter Williams #:

Thanks to you both.  I had trying search and found nothing - hence my question.

Fernando - I guess if I knew  this was a Ternary operator or what a Ternary operator was then I would have found the documentation.

The search engine on this website isn't the best - didn't return anything meaningful for question mark.

Have now followed link to full explanation.

Thanks again to Dominik & Fernando

I did not say anything about searching on the website. I stated that you should in MetaEditor (not website), select the desired section (in this case the question mark) and then hit F1.