Before writing syntax, identify the decision the program must make.
Example requirement:
That contains:
Suppose Player contains:
public bool isAvailable;A matching decision is:
if (player1.isAvailable)
{
System.Console.WriteLine("Player is available.");
}The condition goes inside parentheses.
The controlled statements go inside braces.
A useful sequence is:
requirement
↓
Boolean question
↓
C# condition
↓
controlled actionFor:
the condition is:
team1.score >= 3The complete code is:
if (team1.score >= 3)
{
System.Console.WriteLine("Three or more goals.");
}Requirement:
if (player1.position == "Goalkeeper")
{
System.Console.WriteLine("Use goalkeeper instructions.");
}The equality operator compares the current string value with the expected text.
Requirement:
if (player1.team == null)
{
System.Console.WriteLine("No team assigned.");
}The condition reads the reference state.
It does not create or remove a Team.
Requirement:
if (player1.isAvailable)
{
System.Console.WriteLine("Available");
}
else
{
System.Console.WriteLine("Unavailable");
}The else block runs when the if condition is false.
If the requirement says only:
then:
if (player1.position == "Goalkeeper")
{
System.Console.WriteLine("Use goalkeeper instructions.");
}is enough.
Do not invent a second action when the requirement does not specify one.
Requirement:
Use:
if (team1.score >= 3)
{
System.Console.WriteLine("High scoring");
}The phrase:
at leastincludes 3 itself.
Readable source:
if (team1.score >= 3)
{
System.Console.WriteLine("High scoring");
}
else
{
System.Console.WriteLine("Below 3");
}The visual structure makes the controlled blocks clear.
Suppose the diagram says:
Is the player available?
true → Display "Available"
false → Display "Unavailable"The C# can be:
if (player1.isAvailable)
{
System.Console.WriteLine("Available");
}
else
{
System.Console.WriteLine("Unavailable");
}The diagram and source should describe the same behavior.
For:
if (player1.position == "Goalkeeper")
{
System.Console.WriteLine("Goalkeeper");
}
else
{
System.Console.WriteLine("Field player");
}read:
If that sentence does not match the requirement, revise the code.
For CO-045, write:
if;if/else.Writing chained and nested conditional structures is taught in the next batch.
if (booleanExpression)
{
// action when true
}if (booleanExpression)
{
// action when true
}
else
{
// action when false
}