Page 80 - iPlus_Ver_2.0_class_8
P. 80

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 as shown:





                                                                                        #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
                  evaluated  first  and  if  it  returns  true,  then  the  statements         Conditional     False
                                                                                               Expression
                  inside the loop are executed.
                  The syntax of the while loop is as follows:
                  while(< conditional expression >)                                                   True

                  {
                                                                                           while Loop Body
                         [statements]
                         [increment/decrement expression]
                  }
                  For example,
                  public class WhileLoop
                                                                                                  Stop
                  {
                      public static void main(String args[])                              Flowchart of while loop


                    78
                         iPlus (Ver. 2.0)-VIII
   75   76   77   78   79   80   81   82   83   84   85