Can someone please tell me what the ? does (i.e. mean) in this line of code?
int incColour = decColour == 2 ? 0 : decColour + 1;
Thanking you in advance of your answer.
Can someone please tell me what the ? does (i.e. mean) in this line of code?
int incColour = decColour == 2 ? 0 : decColour + 1;
Thanking you in advance of your answer.
It's called the "ternary" operator.
Essentially it's equivalent to:
int incColour;
if (decColour == 2) incColour = 0; else incColour = decColour + 1;
EDIT: Please ignore the following brain fart of mine.
Which BTW could be more simple stated as:
int incColour = (decColour == 2) ? 0 : 3;
Delta_G:
any other number you add one. 3 would therefore never be an option.
Whoops, that was silly mistake there. :o Of course you are correct. ![]()
Read this:
Sciencez:
Can someone please tell me what the ? does (i.e. mean) in this line of code?int incColour = decColour == 2 ? 0 : decColour + 1;
Thanking you in advance of your answer.
Look at it this way:
ANSWER = (YESNO) ? YES : NO;
That is, if "YESNO" is true, then "ANSWER" is set to "YES". If "YESNO" is false, than "ANSWER" is set to "NO".
Look a different way:
ANSWER = TRUE ? YES : NO (answer will be set to "YES")
ANSWER = FALSE ? YES : NO (answer will be set to "NO")
ANSWER = (1) ? YES : NO (answer gets set to "YES" because "1" is true)
ANSWER = (0) ? YES : NO (answer gets set to "NO" because "0" is false).
Hope this helps.