</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Conditions & Branching

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects
Lesson 5 of 8·Beginner

Conditions & Branching

Let a program make a decision by choosing different instructions for different situations.

Related:conditionbooleanifelsebranch

Conditions let programs choose

A condition is a yes-or-no question the program can answer.

If the answer is yes, run one set of instructions. Otherwise, run another. It is the programming version of: IF it is raining, take an umbrella. OTHERWISE, leave it at home.

Try it: Create a plain-English IF/OTHERWISE decision for whether you should wear a coat.

Write the decision in plain logic

This program checks an age and selects one of two messages.

Pseudocode
CREATE age AS 20

IF age GREATER OR EQUAL TO 18 THEN
    SHOW "Adult"
OTHERWISE
    SHOW "Minor"
END IF
Only one branch runs: the IF branch when the condition is true, or OTHERWISE when it is false.

The same idea in Python

Python uses if and else, with indentation showing which statements belong to each branch.

Python
age = 20

if age >= 18:
    print("Adult")
else:
    print("Minor")

The same idea in JavaScript

JavaScript places the condition in parentheses and branch instructions inside braces.

JavaScript
const age = 20;

if (age >= 18) {
    console.log("Adult");
} else {
    console.log("Minor");
}

The same idea in C#

C# expresses the same decision with if and else.

C#
int age = 20;

if (age >= 18)
{
    Console.WriteLine("Adult");
}
else
{
    Console.WriteLine("Minor");
}

The same idea in Java

Java is nearly identical to C# for this simple decision.

Java
int age = 20;

if (age >= 18) {
    System.out.println("Adult");
} else {
    System.out.println("Minor");
}

The same idea in C++

C++ again uses the same underlying branch structure.

C++
int age = 20;

if (age >= 18)
{
    std::cout << "Adult\n";
}
else
{
    std::cout << "Minor\n";
}
Lesson 5 of 8 · Concept
← Previous Lesson: SequenceNext Lesson: Loops →

Learn to Write Code

Learn the idea first, write it in pseudocode, then see how real programming languages express the same logic.

Learn

CurriculumPseudocode StandardLanguagesReal Code

Elsewhere

Code TalkAbout BriancodeBetter on YouTubeSupporting files on GitHubAdvertising & Promotions
© 2026 Learn to Write Code. Educational content and examples are provided for learning purposes.