One of the most important abilities of any computer program is the ability to make decisions.
Should a user be allowed to log in?
Should a student pass a class?
Should an online order qualify for free shipping?
Programs answer questions like these using conditional statements.
Conditional statements allow software to evaluate information and choose different actions based on the results.
In WGU D278: Scripting and Programming Foundations, understanding conditionals is essential because they appear throughout programming logic, pseudocode, algorithms, and the Objective Assessment.
This guide explains conditional statements, comparison operators, Boolean expressions, common mistakes, and how to solve conditional logic questions on the OA.
What Is a Conditional Statement?
A conditional statement allows a program to make decisions.
A condition is evaluated.
If the condition is true, one action occurs.
If the condition if false, another action may occur.
Example:
if grade >= 70
passIf the grade if 70 or higher:
passIf not:
do not passThe program chooses a path based on the condition.
Why Are Conditional Statements Important?
Without conditionals, software could never react to information.
Consider a few examples
ATM
if pin in correct
allow accessOnline Store
if cart total > 50
free shippingSchool System
if score >= 70
passAlmost every program uses conditional logic.
Understanding True and False
Conditional statements depend on Boolean values.
A boolean can only be True or False.
Every condition ultimately evaluates to one of these values.
Example:
grade >= 70If:
grade = 85the condition becomes:
85 >= 70Result:
TrueComparison Operators
Comparison operators compare two values.
Operator | Meaning |
|---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
These operators frequently appear on the Objective Assessment.
The IF Statement
The most common conditional statement is IF.
Example:
if age >= 18
allow votingThe condition is checked first.
If true: allow voting
If false: Nothing happens
IF-ELSE Statements
Often a program needs two possible outcomes.
Example:
if score >= 70
pass
else
failPossible results:
Student Scores 85
85 >= 70 which means pass
Student Scores 60
60 >= 70 which means fail
IF-ELSE-IF Chains
Programs sometimes need more than two outcomes.
Example
if score >= 90
A
else if score >= 80
B
else if score >= 70
C
else
FThis allows multiple decisions to be evaluated.
Nested Conditionals
A conditional statement can contain another conditional.
Example:
if accountExists
if passwordCorrect
loginThe second condition is only checked if the first condition is true.
Nested conditionals are common in real-world software.
Tracing Conditional Statements
Consider:
score = 75
if score >= 70
pass
else
failStep 1:
75 >= 70
Step 2:
True
Step 3:
pass
The final outcome is:
pass
Common Mistakes Students Make
Mistake #1: Not Evaluating the Condition
Students often jump directly to an answer.
Always evaluate the condition first.
Mistake #2 Confusing Operators
Sometimes students confuse > with >=.
Example:
score >= 70A score of exactly 70 passes.
Example:
score > 70A score of exactly 70 does not pass.
This difference appears frequently on exams.
Mistake #3: Ignoring ELSE
Students sometime focus only on the IF condition.
Remember:
If the IF condition if false, the ELSE branch executes.
Mistake #4: Reading Too Quickly
A question may look similar to another question while producing a completely different result.
Read every option carefully.
Real-World Examples
Login System
if passwordCorrect
login
else
deny accessOnline Shopping
if total >= 50
free shipping
else
shipping feeGaming
if health <= 0
game overObjective Assessment Tips
When solving conditional questions:
- Read the condition carefully.
- Substitute actual values.
- Evaluate the comparison
- Determine whether the result is True or False.
- Follow the correct branch.
Do not skip steps.
Many OA mistakes happen because students assume instead of evaluating.