Page 89 - 2611_SmartGPT Pro V(5.0) C-8
P. 89

On executing the above program, you will get the following output:

                     Output

                  the sum of the first five natural numbers is 15







                                   Imagine you possess the power of the jump statement, allowing you to leap to any part of
                                   the universe. Where would you jump to, and what quests or missions would you undertake
                                   in each dimension?





                                                                                            21 st   #Initiative
                                                                                          Century
                                                         Self Reflection                   Skills  #Leadership & Responsibility
                  A few of your friends have been editing and sharing codes of other classmates without their knowledge. What
                                                         Self Reflection
                  would you do in such a situation?






                        Hashtag


                      #Infinite Loop: The infinite Loop never terminates and continues to run indefinitely when the given
                      condition never becomes false.
                      #Jump Statement: Controls the flow of the code and alters the normal sequential execution of
                      statements.






                      REVISIT



                   ▶   The statements that are used to repeat a set of instructions are called iterative or looping statements.

                   ▶   Python provides two types of looping statements—for and while.

                   ▶   The for statement executes a simple or compound statement for a fixed number of times.

                   ▶   The range( ) function is an in-built function of Python.

                   ▶   A sequence is a succession of values bound together by a single name.
                   ▶   The while statement executes a set of statements repeatedly, until the logical expression evaluates to true.
                   ▶   To come out of the infinite loop, we can either close the program window or press Ctrl + C.

                   ▶   The else block is executed when the condition given in the while statement becomes false.

                   ▶   The break is a keyword in Python which is used for bringing the program control out of the loop.


                   ▶   When a continue statement is encountered inside a loop, control of the program jumps to the beginning of
                     the loop for next iteration, skipping the execution of rest of the statements of the loop.






                                                                                                  Loops in Python  87
   84   85   86   87   88   89   90   91   92   93   94