Okay, so I'm going to start with showing the working version of my while and if-check loop:
int letterIndex = 0;
int rows = sizeof letterArr / sizeof letterArr[0];
while(letterIndex < rows) {
if(letter == letterArr[letterIndex][0]) {
break;
} else {
letterIndex++;
}
}
...and then I obviously do some stuff when the loop's condition is no longer true. Cool.
But at first I was trying to break the loop with this condition:
int letterIndex = 0;
int rows = sizeof letterArr / sizeof letterArr[0];
while( (letter != letterArr[letterIndex][0]) && (letterIndex < rows) ) {
letterIndex++;
}
...and I'd just end up in a never ending loop. The second condition letterIndex < rows
never changed its evaluation to false
.
And then when I tried this next configuraiton:
int letterIndex = 0;
int rows = sizeof letterArr / sizeof letterArr[0];
while(letter != letterArr[letterIndex][0]) {
if(letterIndex < rows) {
break;
} else {
letterIndex++;
}
}
...I was super confused with what was going on. For some reason I switched the condition statements so letterIndex < rows
broke the while loop but that just makes this more confusing for me. In this context shouldn't letterIndex < rows
and letter == letterToArr[letterIndex][0]
be interchangeable?
I printed out a ton of debugging messaging around the variable's values and from the outputted statements the other two versions on this code should be working like I'd assume: when the letterIndex
is more than the rows
value then the statement evaluates to false
.
I'm not sure if this is super helpful but I'm working on an Arduino Uno board and I'm more of a web developer. I've dabbled in C++ but I've never done anything professional with it so no doubt this is due to my lack of understanding/knowledge for either the Arduino architecture or C++. Possibly both.