xxxxxxxxxx
// for else statement like python
for (int i = 0; i < foo; i++) {
if ( breakCondition(i) )
goto breakLabel; // use goto instead of break;
}
baz(); // only activate baz if for was not "broken"
breakLabel:
//...//
xxxxxxxxxx
if (5 == 4) {
//code you want to run if the condition is true
} else {
// code you want to run if the condition is false
}
xxxxxxxxxx
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
xxxxxxxxxx
int time = 20;
if (time < 18) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
xxxxxxxxxx
// 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;
}