Control Flow

If-Else

Make decisions in your code.

Basic Syntax

if (condition) {
    // code
} else if (anotherCondition) {
    // code
} else {
    // code
}

Example

int age = 18;

if (age >= 18) {
    std::cout << "Adult" << std::endl;
} else {
    std::cout << "Minor" << std::endl;
}

Ternary Operator

Short form for simple if-else:

int score = 85;
std::string result = (score >= 60) ? "Pass" : "Fail";
Visualizer
$ ./grades
Grade: B

Interactive Visualization

c
Loading...
Output
Run execution to see output...