Home TechnologyComputers Subscribe to RSS

Explain The "If" Statement Use In C++ Language?

Answer Question

2 Answers - Sort by: Date | Rating

    If statement is used for a decision on the given expression, if the given expression is true then the statement in "if" statement body will execute otherwise not. If statement is often used with else, and called "if else". If the expression is true then the body of "if" will execute other wise the body of "else" will execute.

    The example of "if" statement

    if(a == 10)
    {
    cout<<"Hello";
    }

    And the structure of if-else statement

    if(a == 10)
    {
    cout<<"Hello! How are you?";
    }
    else
    {
    cout<<"Hi! I am fine.";
    }
    0 0

    White 

    answered 3 years ago

      The "if statement" is used to execute (or ignore) a set of statements after testing a condition.
      The "if statement" evaluates a condition. If the given condition is true, the statement ( or a set of statements) following the "if statement" is executed. If the given condition is false, the statement ( or set of statements) following the "if statement" condition is ignored and the control transfer to the next statement.
      The syntax of the "if statement" is:
      If 9condition)
      Statements-1;
      Statement-2;
      Condition: specifies a condition or a relational expression. When this condition is true, the statement following the "if statement" is executed. If the given condition is false, the statement following the "if statement" is ignored and the control transfers to the next statement.

      In the above syntax, only statement –1 will be executed if the given condition is true otherwise the control shifts to Statement-2 that comes after the Statement-1.
      To execute a set of statements following the "if statements", the set of statements is enclosed in curly braces, i.e. within {}. The statements in braces are also known as compound statements.
      If (condition)
          {
      Statement-1
      Statement-2
      Statement-3
      Statement-m
          }
      Statement-n
      0 0

      Pretty123 

      answered 3 years ago

      Nice answer
      Report
      Akhilsingh

      Akhilsingh

      commented 3 months ago

        Answer Question - Answers are editable for 5 min.

        If you do not Sign-in or Register your answers will

        be anonymous, your answers may also be

        checked before going online.

        0

        More

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International