Wednesday, December 21, 2011

Statements


STATEMENTS
A statement in a computer program carries out some action. There are three type of statements used in C++; they are expression statement, compound statement, and control statement.

(i)   Expression statement  An expression statement consists of any valid C++ expression followed by a semicolon. The expression statement is used to evaluate a group of expressions.
    For example,
          x = y;  / / the value of y is copied to variable x
          sum = x+y / / the value of x is added with the value of y
                            / / and then assign to the variable sum     
(ii)  Compound statement   A group of valid C++ expression placed within a { and } statement is called a compound statement. The individual statement may be of an expression statement, a compound statement or even a control statement. Note that the compound statement is not completed with a semicolon.
     For example,
         {
                  a = b+c
                  x = x*y
                  y = a+x
         }
(iii) Control statement   The control statement is used for the program flow and to check the conditions of the given expression or a variable constant. The keywords of the control statements are normally a predefined or reserved words and programmer may not use them a ordinary variables.
  For example,
    (1)
          if   (a >b)   {



                                     
          }
   (2)
          while   (condition is becoming true)   {
        


                          
         }

1 comment: