Page 76 - iprime_V2.2_class8
P. 76

5                            Conditional, Loop



                                                   and Jump Statements



                                                                         in Java






                           Chapter Profile
                              Conditional Statements                              Loop Statements
                              Jump Statements                                     Errors in Java
                              Writing Some More Programs




                  The programs we have written so far were executed statement by statement in a top-to-bottom
                  approach. However, sometimes we need to change the order of execution for statements or
                  repeat some statements a certain number of times. Additionally, there are some situations where
                  we need to stop the execution of certain statements. Java provides three types of statements to
                  handle these requirements:
                      Conditional Statements
                      Loop Statements
                      Jump Statements

                  Let us learn about these in detail.
                      CONDITIONAL STATEMENTS

                  Conditional statements allow us to change the default flow of a program. They transfer control of
                  a program from one statement to another, depending on the condition provided. If the provided
                  condition returns true, a block of specified statements is executed. Conditional statements are
                  also known as decision-making statements.
                  There are four decision-making statements in Java:

                      if statement
                      if … else statement
                      if … else… if statement

                      switch statement
                  Let‘s learn more about them.
                  The if Statement

                  The if statement is the most basic conditional statement in Java that allows us to test a condition
                  before executing a block of statements. If the provided conditional expression returns true, the
                  statements specified in the body of the 'if' statement are executed.


                  74     iPRIME (Ver. 2.2)–VIII
   71   72   73   74   75   76   77   78   79   80   81