Page 178 - Computer science 868 Class 12
P. 178

2.  Expression statement: An expression statement contains an expression. Variables, operators, literals and method
                 calls are all part of the Java expression and always evaluate a single value.
                For example:
                   double radius = 2.2, area;
                   area = 3.142 * radius * radius;
                Here, the first statement is a declarative statement and the second statement is an expression statement.
              3.  Control flow statement: Normally all statements execute in sequential order, but sometimes it becomes necessary
                 to execute a set of statements repeatedly for a number of times or as required by the condition of the program. This
                 is done by the control flow statements or control statements.
                Control statements are used to decide in which direction the program will execute. There are mainly four types of
                 control statements. They are:
                •  Sequential statements
                •  Conditional statements
                •  Iterative statements
                •  Jump statements


                   7.1 SEQUENTIAL STATEMENTS
              These statements normally execute sequentially from top to bottom in the order that the code appears. It follows the
              Top – Down approach.
              For example:

                   class cal
                   {
                       public static void main(int side)
                       {
                           int area;
                           area = side * side;
                           System.out.println("Area of a square : " +area);
                       }
                   }

                   7.2 CONDITIONAL STATEMENTS
              According to the need of the program, the execution of the statements are directed on the basis of a condition. If the
              condition is satisfied, then the statements given in the true part of the conditional statement is executed, otherwise
              the statements in the else part will be executed. The conditional statements are of three types. They are:
              •  if statement
              •  ternary operator
              •  switch statement

              7.2.1  ‘if’ statement
              The ‘if’ statement consists of the statements given in its true as well as else parts and executes either set of statements
              based on the result of a given condition. There are five types of if statements. They are:
              •  simple if statement
              •  if-else statement
              •  if and only if statement
              •  if else if statement
              •  nested if statement


                176176  Touchpad Computer Science-XII
   173   174   175   176   177   178   179   180   181   182   183