If and else statements(C++)
Umid2008
Posted on March 24, 2023
Hello, today we will talk about if and else statements.
The operator" If/else", is called the" condition " operator in C++.
If one condition holds, the If/else operator is used in C++ code. It is an operator, a type of operator where the program can perform actions under all conditions.
Example for If/else:
#include <iostream>
using namespace std;
int main() {
int a = 10;
if (a > 5) {
cout << "a is greater than 5";
} else {
cout << "a is less or equal than/with 5";
}
return 0;
}
In the above code, if variable A is greater than 5, the text "a greater than 5" is output. In another case," A is less than or equal to 5 " must be output.
The syntax used is as follows:
if (conditions) { // if conditions are true, actions must be performed } else { //otherwise, actions must be performed }
If the conditions are correct, the" if "block is executed and otherwise The" else " block is executed.
Posted on March 24, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.