Page 116 - CA_Blue( J )_Class10
P. 116

07                                CONDITIONAL



                                                                    CONSTRUCTS IN JAVA















                        Learning Objectives



                   7.1 Flow of Control                           7.2 Conditional Statements
                   7.3 Ternary Operator                          7.4 Switch Case Statement
                   7.5 Fall-Through Situation                    7.6 Difference Between if Statement and switch Statement
                   7.7 Menu Driven Program using switch Statement  7.8 Terminate Program Using System.exit()





              While coding, there are some statements that are required to validate the criteria as asked in the program. These
              statements change the normal flow of the program and execute the part which satisfies the criteria. Thus, affects the
              flow of control of the program.


                   7.1 FLOW OF CONTROL
              In Computer Science, flow of control means the way in which sequence the program executes so that the correct
              output is generated. There are three types of flow of control that are related to programming:
              •  Normal flow of control
              •  Conditional flow of control
              •  Multi branching flow of control
              Let us study about them in detail.

              7.1.1 Normal Flow of Control
              Normal flow of control is the default procedure by which the control of the program code executes according in a
              top-down manner which means that the statements are executed according to the order in which they are written.
              It is also known as sequential flow of control. In case of normal flow of control, the control keeps on executing from
              the first statement and continues till the last statement. The programs you have developed till now are executed
              sequentially in a top-down approach. Let us take an example of normal flow of control.

                Program 1    To input principal amount, rate of interest and time and then calculate the simple interest.

                 1  import java.util.*;

                 2  class simple_interest

                 3  {



                114114  Touchpad Computer Applications-X
   111   112   113   114   115   116   117   118   119   120   121