Page 79 - iprime_V2.2_class8
P. 79

The if...else...if Statement

                 The if…else…if statement helps us to test multiple conditions and execute one of the multiple
                 blocks of statements. These blocks are specified by 'if' and 'else...if' keywords. The 'else' block
                 will be executed if any of the given conditions in the 'if' and 'else...if' blocks does not evaluate to
                 true. The 'if...else...if' statement is also known as the if…else ladder.

                 The syntax of the 'if...else...if' statement is as follows:
                 if (< conditional expression >)

                 {
                        [statements]
                 }

                 else if(< conditional expression >)
                 {
                        [statements]

                 }
                 ……
                 else

                 {
                        [statements]

                 }
                                               Start






                                           Conditional       False
                                           Expression

                                               of if


                                                  True         Conditional      False
                                                               Expression

                                            Body of if          of else if

                                                                     True

                                                             Body of else if     Body of else






                                               End
                                                     Flowchart of if....else....if statement





                                                                  Conditional, Loop and Jump Statements in Java    77
   74   75   76   77   78   79   80   81   82   83   84