Page 113 - Trackpad_V1_Book 8_Flipbook
P. 113

You will get the following output:






















                 The above example prints all the numbers in the range before the number 6. This is because when
                 the value of i equals 5, the break statement will force the program to exit from the loop.


                 THE continue STATEMENT
                 The continue statement causes the program to skip the rest of the statement of the current block
                 and move to the next iteration of the loop. It immediately transfers control to the evaluation of the
                 test expression of the loop for the next iteration of the loop.

                 Program 9: To demonstrate the use of the continue statement












                 You will get the following output:






















                 The example above prints all the numbers except 5 because when the value of i is equal to
                 5, the continue statement placed inside the if statement will force the program to skip the
                 iteration.






                                                                                        Control Structures in Python  111
   108   109   110   111   112   113   114   115   116   117   118