When a decision behaves unexpectedly, first identify:
Then use the debugger to compare your prediction with the actual execution path.
Consider:
if (player1.isAvailable)
{
System.Console.WriteLine("Available");
}
else
{
System.Console.WriteLine("Unavailable");
}Pause before or on the decision and inspect:
player1.isAvailableSuppose it is:
falsePredict:
if block → skipped
else block → runsThen step through the decision.
For:
if (player1.position == "Goalkeeper")inspect:
player1.positionIf the debugger shows:
"Forward"predict:
"Forward" == "Goalkeeper" → falseThe true block should be skipped.
Suppose:
if (team1.score >= 3)Check important values:
2 >= 3 → false
3 >= 3 → true
4 >= 3 → trueIf the code behaves incorrectly at the boundary, inspect whether the operator matches the requirement.
For:
if (player1.team == null)inspect:
player1.teamIf it shows:
nullpredict true.
If it shows an actual Team object, predict false.
Use F10 / Step Over.
For a basic if/else:
condition true → enter if block
condition false → enter else blockThe highlighted source path provides runtime evidence.
Suppose you expected:
score = 3but the debugger shows:
score = 0The defect may occur before the if.
Ask:
A correct condition can still choose the wrong path if its input state is wrong.
Consider:
if (player1.isAvailable)
{
System.Console.WriteLine("Unavailable");
}
else
{
System.Console.WriteLine("Available");
}If:
isAvailable = truethe debugger correctly enters the if block.
The condition is working.
The branch action is wrong.
Debugging means comparing both the path and the action with the requirement.
Suppose:
player1.DisplayStatus(false);calls:
public void DisplayStatus(bool available)
{
if (available)
{
System.Console.WriteLine("Available");
}
else
{
System.Console.WriteLine("Unavailable");
}
}Trace:
argument false
↓
parameter available = false
↓
condition = false
↓
else blockThe debugger can confirm each stage.
If the condition is inside a method, the Call Stack can help identify which caller brought execution there.
That matters when the same method can be called from several places with different arguments.
Avoid random edits.
A stronger process is:
read requirement
↓
inspect runtime values
↓
evaluate condition
↓
predict branch
↓
step through
↓
compare observed behavior
↓
correct the specific defectThis activity focuses on debugging:
if;if/else.Debugging chained and more complex conditional return behavior is taught later.
A strong debugging explanation connects:
That evidence tells you whether the defect is in the input state, the condition, or the action inside the branch.