i’ve came across a simple loop which seems to go into the loop regardless of a parameter i query in order to determine whether the loop should process. Below is the loop;
if (result[4] == 0x01 || result[5] == 0x01 || result[6] == 0x01 || result[7] == 0x01 || result[8] == 0x01 || result[9] == 0x01 & deviceState == false)
{
deviceState = true;
mainUI.setAlarmColour(result, device);
}
note: i’ve tried “&” and “&&” for the final parameter, but both make no difference.
With this loop, even if deviceState is set to true, it proceeds to enter the loop. However, if i use the following loop it stops this issue:
if (result[4] == 0x01 || result[5] == 0x01 || result[6] == 0x01 || result[7] == 0x01 || result[8] == 0x01 || result[9] == 0x01)
{
if (deviceState == false)
{
deviceState = true;
mainUI.setAlarmColour(result, device);
}
}
This second loops solves the problem and it no longer proceeds into the loop, meaning my function isn’t called.
am I missing something fundamental here? I’ve tried messageBoxes to verify that it’s false and they return the way I’d expect, yet it still enters the first loop.
First it’s
&&like you already tried (&is a bitwise operator), but you should group yourORs together and have the finalANDstandalone, like so:Note that you can also change
deviceState == falseto simply!deviceState(if it’s a non-nullablebool).!flips false to true for the comparison so you’re essentially saying the exact same thing, albeit shorter.(Please ignore ugly formatting, just trying to show it clearer)