Hi there, I’m trouble with an if statement. My code is too long for pasting it here to be practical, but here’s a really simplified equivalent scenario.
int index = 0;
int Pressure = 0;
index = myString.indexOf("trigger");
if (Pressure == 0 && index > 0)
Pressure = 100;
...SOME INDICATOR CODE...
Where myString is updated frequently in the other portion of the code, and the Indicator code just shows that the if statement was activated.
To me, this seems like it should run the first time that the keyword “trigger” is in myString, and then never again because the Pressure condition is no longer met.
However, what actually happens, according to that indicator (lets say its an LED), is that the if statement runs every single loop, regardless of what either the index or pressure is equal. Both of the conditions could be false and this if statement still runs for some reason.
Sorry for the unusual way of explaining that, it’s just not practical for me to paste my actual code because of length and complexity. If there’s anything I can explain better, let me know. Thanks in advance for the help!
Also the omitted code may well interfere with your subsequent checks, so you need to browse for any instance where Pressure could be reset to 0 or double check your indicator logic - maybe it’s just not reset when the condition is not met - at least the way how you indicate the met condition would be good to see
@HEng, I’ve reformatted the code block, but actually the preformatted text feature isn’t the right one to use for blocks of code. For these you’d use a line with ```cppbefore the block of code and with ```after (each by itself without any leading or trailing whitespace)
For more infor about the formatting features of Discourse (with which this forum is built) can be found here