Page 74 - iPlus_Ver_2.0_class_8
P. 74

Conditional, Looping and



                       Jumping Statements in


                       Java                                                                5










                          Learning Outcomes



                              Conditional Statements                             Looping Statements

                              Jumping Statements                                 Errors in Java

                              Writing Some More Programs





                  The programs we have written till now were executed statement by statement in a top-to-bottom
                  approach. Sometimes, we need to change the order of execution for statements. We also need
                  to repeat some statements a certain number of times. Apart from these, some situations occur
                  when we need to stop the execution of any statement. To do this, Java provides three types of
                  statements, which are as follows:

                  •  Conditional Statements         •  Looping Statements            •  Jumping Statements
                  Let us learn about these in detail.

                   i +  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 as follows:
                  •  if statement

                  •  if … else statement
                  •  if … else… if statement
                  •  switch statement

                  Let‘s learn about these decision-making statements in Java.
                  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.


                    72
                         iPlus (Ver. 2.0)-VIII
   69   70   71   72   73   74   75   76   77   78   79