If Statements Have Their Own Scope

I just ran into a bug that was the result of thinking that the block inside the body of an if statement had the same scope as the code outside of the if statement.

To clarify, the ‘{}’ in an if statement has its one scope, meaning that it can see the variables from the code outside of the ‘{}’, but that that exterior code is unable to see into the scope of the if statement.

Leave a Reply