Confused about if-else and break statements

Thanks for the explanation :+1: Didnā€™t realize I couldnā€™t define xval3 in a case preceding the one in which I used it in a statement.

You should read up on variable scope in C/C++. It's important to understand that concept. Briefly, a variable that you create in a function or block is local to that function or block, and cannot be seen outside. A block is anything defined within curly braces - so in your case, since you defined xval3 within the curly braces of an if-statement, that variable cannot be seen outside of that if (not even in the else part of the if-else).

2 Likes