Ad Code

Responsive Advertisement

C++ If statement - Learn CPP

C++ If statement - Learn CPPThe conditional if statement is one of the most important functions used in the language, and its way is for the program to verify the fulfillment of the condition as if you are telling the translator if the condition is met, do this. If the condition is met, whatever the result of the comparison is (True), it will perform the steps between the parentheses of the conditional statement (if), and if the condition is not met, meaning that the comparison result was (False), it will cross all the steps in the parentheses of the conditional statement (if). It does not implement it, that is, the result of comparing conditions must be (True) in order for it to be executed between parentheses of the conditional statement, and the code is written in this way:


C++ If statement - Learn CPP



If statement example



if(condition);

{

statement;

}


The statement in parentheses is the condition sentence.


The if expression consists of the keyword if, followed by the decision body. It consists of either one statement or several statements surrounded by brackets {}. The parentheses are fulfilled if the condition is met, but if the condition is not met, nothing is executed.


Note: If we want to print more than one statement within the if statement, we must add {}, and it is not required to write it if it is one statement.

You can read more about STL classes in c++ here.


Relationships that are used as conditions in the if statement


  • The greater sign is denoted by >, how it is represented in conditional if: x>y) if) Comparison of two variables (x,y) Executes the dependent clause of the if statement if x is greater than y.
  • The least sign is <, the way it is represented in the conditional if: x
  • The greater or equal sign =<, the way it is represented in conditional if: x>=y) if) Comparison of two variables (x,y) Executes the dependent clause of the if statement if x is greater or equal to y.
  • The equals sign ==, the way it is represented in conditional if: x==y) if) Comparison of two variables (x,y) Executes the dependent clause of the if statement if x equals y.
  • The not equals sign =!, the way it is represented in conditional if: x!=y) if) Comparison of two variables (x,y) Executes the dependent clause of the if statement if x is not equal to y.
  • Combine two conditions with and and are represented by &&, the way they are represented in the if conditional: ((if ((x>y)&&(x>z), executes the dependent clause of the if statement if x is greater than y and also greater than z i.e. it must be checked The two conditions until the sentences are executed.
  • Two conditions are combined with or and are represented by ||, and the way they are represented in the if conditional is: ((if ((x>y)||(x>z), and it means the execution of the dependent clause of the if statement if x is greater than y and also greater than z i.e. That the two conditions must be met in order for the sentences to be executed.
  • Where (=!,==,=>,=<,>,<) is used as a relationship between two variables or values ​​or a variable and a mathematical expression.