A good answer might be:Here is the example fragment properly indented and with matching if's and else's colored the same.
|
Make Matches clear with BracesSometimes you have to use braces { and } to say exactly what you want. Other times you don't absolutely need them, but using them makes clear what you want. Here is the complete rule, including braces: Rule for Matching if and else: An "else" inside a set of braces cannot match an "if" outside of that pair. Within each pair of matching braces: start with the first "if" and work downward. Each "else" matches the closest preceeding unmatched "if." An "if" matches only one "else" and an "else" matches only one "if."Here is a program fragment that uses braces:
The blue if and blue else match.
Without the braces, they would not match.
Here is another, poorly indented, fragement:
|
QUESTION 12:Match the if's and else's. Click Here after you have answered the question |