Conditional statements in C

Conditional Statements in C

✨ Conditional Statements in C

Conditional statements help control the flow of a program based on conditions.

1️⃣ if Statement

📘 Full Definition

The if statement in C is used to execute a block of code only when a given condition is true. If the condition evaluates to false, the code inside the if block is skipped.

⚡ Shortcut Definition

if = Runs code only when condition is true.

📝 Syntax

if (condition) {

    // statements;

}

2️⃣ if-else Statement

📘 Full Definition

The if-else statement provides two alternative paths of execution. If the condition is true, the if block is executed; otherwise, the else block is executed.

⚡ Shortcut Definition

if-else = Choose between two options (true or false).

📝 Syntax

if (condition) {

    // statements if true;

} else {

    // statements if false;

}

3️⃣ if-else if Ladder

📘 Full Definition

The if-else if ladder allows checking multiple conditions one after another. The program executes the block of the first true condition. If none of the conditions are true, the else block (if present) is executed.

⚡ Shortcut Definition

if-else if ladder = Multiple condition checker.

📝 Syntax

if (condition1) {

    // statements;

} else if (condition2) {

    // statements;

} else {

    // default statements;

}

4️⃣ switch Statement

📘 Full Definition

The switch statement in C is used when there are multiple fixed choices for a single variable or expression. Each choice is handled by a case label, and execution jumps to the matching case. If no case matches, the default block is executed.

⚡ Shortcut Definition

switch = Multi-choice decision maker.

📝 Syntax

switch (expression) {

    case value1:

        // statements;

        break;

    case value2:

        // statements;

        break;

    ...

    default:

        // statements;

}

Comments

frequently used resource

C LANGUAGE

Operators and expressions

Looping statements in c