// 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:
//...//
if (5 == 4) {
//code you want to run if the condition is true
} else {
// code you want to run if the condition is false
}
// 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;
}
int time = 20;
if (time < 18) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
Code Example |
---|
Cpp :: string to char* |
Cpp :: restting a queue stl |
Cpp :: c++ tokenize string |
Cpp :: change int to string c++ |
Cpp :: string to int c++ |
Cpp :: coordinate in 1d array |
Cpp :: iterate vector in reverse c++ |
Cpp :: combine two vectors c++ |
Cpp :: Quicksort taking random pivot |
Cpp :: 2-Dimensional array in c++ |
Cpp :: how to make an overloaded constructor in c++ |
Cpp :: declare nullptr c++ |
Cpp :: c++ vector initialization |
Cpp :: c++ cstring to string |
Cpp :: loop through array c++ |
Cpp :: find duplicate from an array c++ |
Cpp :: sizeof operator in c++ |
Cpp :: c++ average |
Cpp :: to lowercase c++ |
Cpp :: c++ get maximum value unsigned int |
Cpp :: unordered_set to vector |
Cpp :: c++ contains |
Cpp :: new line in c++ |
Cpp :: how to slice vector in c++ |
Cpp :: after login redirect to dashboard in nuxt |
Cpp :: cin exceptions c++ |
Cpp :: c++ write to csv file append |
Cpp :: C++ String Compare Example |
Cpp :: search by value in map in stl/cpp |
Cpp :: double array c++ |