if (selectedMenuItem == mkLoadLabels) {
lcd.print("Loading Labels");
loadLabels(); // <--- IF I UNCOMMENT THIS LINE, I GET THE COMPILE ERROR
}
else if (selectedMenuItem == mkRun)
. . .
In C++, indentation serves only to improve code readability; unlike Python, it does not define the grouping of statements. The structure of an if/else statement looks like this:
if (condition)
statement_if_true
else
statement_if_false
Here, each branch executes a single statement, so if you want to do
if (selectedMenuItem == mkSpeed1)
lcd.print("Slow selected");
then you are fine as lcd.print("Slow selected"); is a single statement.
But if you want to execute multiple statements as a group within an if or else like
if (selectedMenuItem == mkLoadLabels)
lcd.print("Loading Labels");
loadLabels();
it does not work as you have two statements. You need to enclose them in curly braces {}, creating what is known as a compound statement.
{ // this is a compound statement (so just one statement composed of multiple statements)
lcd.print("Loading Labels");
loadLabels();
}
This way, the if or else still contains a single statement—the compound one—while grouping multiple commands together.