Page 239 - IT-802_class_12
P. 239

case 4: day = “Thursday”;

            break;
            case 5: day = “Friday”;
            break;
            case 6: day = “Saturday”;

            break;
            case 7: day = “Sunday”;
            break;
            default: day = “incorrect Day!”;

            break;
            }
            System.out.println (day);
            }

            }




















            3.4.4 Iterative Statements

            Sometimes, we may require to repeat certain lines of the program according to the logic or need of the program. A
            programming language like Java allows the statements to repeat a specified number of times. This repetitive flow of
            control in a program is called a Loop and the repetitive statements are called iterative statements. The loop is used to
            execute a certain number of lines again and again to get the desired result. There are three types of for loops in Java.
            Which are as follows:
            for loop

            while loop
            do-while loop
            3.4.5 The for Loop
            The for loop is the most widely used Java loop construct. The syntax of the Java for statement is as below:

            for (counter=initial_value; test_condition;change counter)
            {

            statements
            }



                                                                               Fundamentals of Java Programming  237
   234   235   236   237   238   239   240   241   242   243   244