DEV Community

Umid2008
Umid2008

Posted on

If and else statements(C++)

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;
}

Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)