The scope of an if clause determines a range over which the result of the condition affects. The scope of an if clause is on the statement which immediately follows the if statement. It can be a simple statement or compound statement.
Case 1:
if (a>b) i = i + 1; // s1 j = j + 1; // s2
Case 2:
if (a>b) { i = i + 1; // s1 j = j + 1; // s2 }
If in Case 1 the if condition is true, then s1 is executed because s1 is a simple statement.
If in Case 2 the if condition is true, then both statements s1 and s2 are executed because s1 and s2 are enclosed in a compound statement.
No comments:
Post a Comment