Page 83 - TP_iPlus_V2.1_Class8
P. 83

When you enter the value 8, none of the cases will be
                 matched. Hence, the default case will be executed and
                 the output “Invalid day number” will be displayed on the
                 terminal.


                                                                                                  Output

                                                                                       #Coding & Computational Thinking

                      Let’s CatCh Up


                   Define the following statements:
                   1. if          -
                   2. if...else   -

                   3. if...else...if  -



                  i +  LOOPING STATEMENTS

                 Looping statements are the control flow statements that allow us to repeatedly execute a set of
                 statements for a given number of times. These are also called iteration statements or loops. Java
                 provides three kinds of looping statements, which are as follows:

                 •  while                    •   do-while                 •   for
                 However, the for loop is more commonly used as compared to the while and do-while loops.

                 Let us learn about these in detail.
                                                                                                  Start
                 The while Loop

                 The while loop is a flow control statement in Java. It is used
                 to execute a block of statements repeatedly until a given
                 condition becomes false. In a while loop, the condition is
                                                                                              Conditional     False
                 evaluated  first  and  if  it  returns  true,  then  the  statements
                                                                                              Expression
                 inside the loop are executed.
                 The syntax of the while loop is as follows:
                                                                                                     True
                 while(< conditional expression >)
                 {                                                                       Body of while loop
                        [statements]
                        [increment/decrement expression]
                 }
                 For example:
                 public class WhileLoop
                                                                                                  Stop
                 {
                     public static void main(String args[])                              Flowchart of while loop


                                                                                                                  81
                                                                 Conditional, Looping and Jump Statements in Java
   78   79   80   81   82   83   84   85   86   87   88