Page 186 - ComputerScience_Class_11
P. 186

After correcting it, the program returns the following output:
              Enter the length and breadth
              20
              10
              Perimeter 60
              Area 200


                   8.3 COMPOUND STATEMENTS
              When a group of statements is written within a curly bracket, then it is known as a compound statement. This group
              of statements executes together in a sequential manner to provide the result.

              These statements are useful for all types of conditional and iterative statements.
              For example,

                  if(a>b && a>c)
                  {
                      System.out.println(a+ "is largest");
                      System.out.println(b + " and" +c+ "are less than" +a);
                  }
                  else if(b>a && b>c)
                  {
                      System.out.println(b+ "is largest");
                      System.out.println(a+ "and" +c+ "are less than" +b);
                  }
                  else
                  {
                      System.out.println(c+ "is largest");
                      System.out.println(a+ "and" +b+ "are less than" +c);
                  }

                   8.4 CONTROL STATEMENTS
              As we have already learnt that the control statements control the flow of a program. They determine whether the
              statements will be executed or not based on certain conditions.
              There are three types of control statements which are as follows:
              •  Sequential Statements
              •  Conditional Statements
              •  Iterative Statements

              Let us learn about them in detail.

              8.4.1 Sequential Statement                                                              Statement 1
              In Java, the statements are executed sequentially which represents the default flow of
              statements. In the default flow of statements, the compiler executes the first statement and
              then goes to the next statement for its execution and so on, unless it receives a conditional   Statement 2
              or an iterative statement. The sequential statement follows the top-down approach.
              The following program shows the sequential flow of statements.                          Statement 3





                  184  Touchpad Computer Science (Ver. 3.0)-XI
   181   182   183   184   185   186   187   188   189   190   191