if statement in c++ with example.

what is the if statement in c++ and how do we use the if statement in the c program?

if statement in c++ with example.

  • if statement in c++

The if statement is a decision-making statement.  if statement is the simplest form of the decision statement.The if statement is also called a decision-making statement. It tests a relationship, using the relational operator. And makes a decision about which states to be executed next, based on the result of the decision. . It is used to execute or skip a statement or set of a statement by checking conditions. The statements inside the body of “if” only execute if the given condition returns true. If the condition returns false then the statements inside “if” are skipped. An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Below is a general example of an if statement, not specific to any particular programming language...



                The condition is given as a relational expression. If the condition is true, the statement or set of statements after if statement is executed. If a condition is false, the statement or set of statements after if statement is not executed.

Syntax of if statement

If the statement of if statement is only one then we write the statement of the if statement like this.

Single statement;

                     If (condition)

                     Statement;

The above statement is used for a single statement. The single statement doesn’t need bracket { }.

Multiple statements

If the statement is multiple or more than two statements then we used a curly bracket with the body of the if statement.

Multiple statements

                     If (condition)

                       Statement 1;

                       Statement 2;

                       Statement 3;

                        .

                        .

                        .

                      Statement n;

The above statement is used for multiple if statements.

 Limitation of if statement

 The assuming assertion is the basic choice construction yet it is exceptionally restricted in its utilization. The assertion or set of explanations is executed assuming that the condition is valid. Be that as it may, in the event that the condition is bogus, nothing is executed.

  • Execute one statement or set of the statement if the condition is true.
  •  Execute another statement or set of the statement if the condition is false.


if statement in c++ with example.
if statement in c++ with example.