C/C++ Arena

Step 1 of 6

if and else

if runs a block of code only when a condition is true. else runs when it's false.

if (hp > 0) {
    printf("alive\n");
} else {
    printf("dead\n");
}

Comparison operators: == equal, != not equal, <, >, <=, >=.

Careful: = assigns and == compares. if (x = 5) is a classic bug.

Your turn: read a health value and print alive if it's greater than 0, otherwise dead.

Next: else if chains