A nested if places one decision inside the true branch of another. The inner condition is evaluated only after the outer condition succeeds. This is useful when a second check makes sense only for a qualified object.
if (isMember)
{
if (age < 12)
{
ticketPrice = 5;
}
}Here, a visitor’s age matters for the child member price only after membership is confirmed. When isMember is false, execution skips the entire outer body, including the age comparison. When it is true and age is 8, ticketPrice becomes 5. The surrounding method must still define the price for the other paths.
The inner diamond belongs on the outer Yes path. Moving it after the outer branches rejoin would incorrectly check age for nonmembers. A nested if is a way to show dependent checks; an else if instead checks a different alternative after the first condition fails.
Trace three visitors: a nonmember aged 8, a member aged 8, and a member aged 12. Mark which tests are actually evaluated for each visitor, then identify which value of ticketPrice must already be set before this code runs.
This fragment leaves the price unchanged on paths that do not select the child member price. For a complete pricing method, initialize ticketPrice to the regular price before the nested if or assign it on every path. The code illustrates when the inner condition is reached; it does not by itself specify all ticket prices.