Page 314 - Computer Science V2.0 Class 11
P. 314

False       Test
                                                                condition



                                                                     True

                                                               Enter Loop




                                                                Continue
                                               Exit Loop

                                                  Fig 11.5: Working of continue statement
              As the control moves to the next iteration, firstly, the loop variable is updated with the next value in the sequence
              or range. Thereafter, if the updated loop variable is within the range/ sequence or if the test condition is True, the
              execution of the statements in the body of the loop takes place. Consider the examples given below, that explain the
              working of continue statement in for loop and while loop.


                            for x in range(1, 5):                  num = 5
                                if x == 3:                         while num <= 10:
                                    continue                           if num % 4 == 0:
                                else:                                      num = num + 1
                                    print(x)                               continue
                            print('Over')                              else:
                                                                           print(num * num)
                                                                           num = num + 1
                                                                   print("Done")

                            Output:                                Output:
                            1                                      25
                            2                                      36
                            4                                      49
                            Over                                   81
                                                                   100
                                                                   Done



                     break and continue statements are usually part of the body of the if statement.



               Program 11.9 To accept five numbers (except 0) and display their product.
                01 #Objective: To accept five numbers (except 0) and display their product.
                02 P = 1
                03 for count in range(1, 6):
                04     num=int(input('Enter a number :  '))
                05     if num == 0:
                06      print(' ZERO will not be multiplied')

               300   Touchpad Computer Science (Ver. 2.0)-XI
   309   310   311   312   313   314   315   316   317   318   319