No, I don't think the loop would be optimized away. I'm not sure what you have in mind there.
0 & a & b & c & d & e & f is false for any values of a, b, c, d, e, f;
EEs tend to know this because the AND gate's output is zero whenever any of its inputs is zero. Put another way, the
success condition in your code starts out false, and the AND operator can never become true when it has any false inputs. So the loop cannot, by construction, alter the value of
success. The C compiler should therefore consider the entire loop as dead code, since it has no effect on the program and does not involve
volatile variables.
There are also other problems in the code, such as the absence of blocks (compound statements) following
for and
if. This leads to "dangling if" problems where the scope of the
if is not what it appears to be on the screen. That's the case in your code: the simple omission of a semicolon means that the
if is actually inside the loop!
int success = 0;
for (int i=0; i<6; ++i)
success &= input[i] == secret[i] if (success) turnOnSolenoid();
This will produce a syntax error at compile time, but there are other situations where it would pass unnoticed (comma...)