if

Consists of a boolean expression (evaluating to true or false), followed by one or more statements.

 

Can be followed by an (optional) else statement.

 

 

Simple code to show if condition is true:

#include <stdio.h>

int main() {

    int myVar = 42;

    if (myVar < 100) {
        printf("myVar is less than 100 \n");
    } else {
        printf("myVar is greater than 100 \n");
    }
return 0;
}

 

Simple code to show if condition is false:

#include <stdio.h>

int main() {

    int myVar = 269;

    if (myVar < 100) {
        printf("myVar is less than 100 \n");
    } else {
        printf("myVar is greater than 100 \n");
    }
return 0;
}

Leave a Reply