if-else statement helps make decisions in your program. It checks a condition (a true or false statement) and runs code based on whether the condition is true or false.

Here’s how it works:

  1. If statement: It checks if a condition is true. If the condition is true, the code inside the if block runs.
  2. Else statement: If the condition is false, the code inside the else block runs.

Example:

#include <stdio.h>


int main() {

    int number = 10;


    // Check if number is greater than 5

    if (number > 5) {

        printf("The number is greater than 5\n");

    } else {

        printf("The number is 5 or less\n");

    }


    return 0;

}


How it works:

  • In this example, the condition is number > 5.
  • If the number is greater than 5, the program will print "The number is greater than 5".
  • If the number is not greater than 5 (false), the program will print "The number is 5 or less".

Key points:

  • The condition in the if statement must be something that can be either true or false.
  • The else part is optional, and you only use it when you want to do something different if the condition is false.

Comments

  1. ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️

    ReplyDelete

Post a Comment

Popular posts from this blog