If and else statements(C++)

umid2008

Umid2008

Posted on March 24, 2023

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.

💖 💪 🙅 🚩
umid2008
Umid2008

Posted on March 24, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

If and else statements(C++)
webdev If and else statements(C++)

March 24, 2023