if (condition)
{
// block of code
}
else if (condition)
{
// block of code
}
else {
// block of code
}
if (condition) {
// block of code to be executed if the condition is true
}
//1
if(condition) {
statement(s);
}
else {
statement(s);
}
//2
(condition) ? (true_statement) : (false_statement)
// C program to illustrate If statement
#include <stdio.h>
int main() {
int i = 20;
if (i < 15){
printf("i is smaller than 15");
}
else{
printf("i is greater than 15");
}
return 0;
}
bool state = (value > 0) ? true : false;
1 == 2 || 4
if (condition) {
// body of if statement
}
if(condition)
{
// Statements to execute if
// condition is true
}
int x = 20;
int y = 18;
if (x > y) {
cout << "x is greater than y";
}
int time = 20;
string result = (time < 18) ? "Good day." : "Good evening.";
cout << result;