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
}
// C++ program to illustrate if-else statement
#include<iostream>
using namespace std;
int main()
{
int i = 20;
if (i < 15)
cout<<"i is smaller than 15";
else
cout<<"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;