Page 158 - CA_Blue( J )_Class9
P. 158

08                                CONDITIONAL




                                                                     CONSTRUCTS IN JAVA














                            Learning Objectives


                            8.1 Flow of Control

                            8.2 Difference between if Statement and switch Statement

                            8.3 Terminating a Program using System.exit()




                  Normally, coding of programs starts from the first line to the last line. But sometimes according to the requirement,
                  the execution of the code changes its directions. Thus, affecting the flow of control of the program code.


                       8.1 FLOW OF CONTROL
                  The sequence in which a program's instructions are executed to generate the correct output is called Flow of
                  Control. Generally, there are three types of flow of control. They are:
                  1.   Normal flow of control
                  2.   Conditional flow of control
                  3.  Multiple branching of control

                  8.1.1 Normal Flow of Control
                  By default, the control of a program code executes in a sequential manner. Here the control keeps on executing
                  from the first statement and continues till the last statement.

                  Example of Normal flow of control,


                   Program 1      To input three numbers and print their sum and average.

                     1     import java.util.*;

                     2     class sum_and_average
                     3     {

                     4         public static void main ()





                   156    Touchpad Computer Applications-IX
   153   154   155   156   157   158   159   160   161   162   163