Page 253 - AI Computer 10
P. 253

Iterative Statement
        Iterative statement or looping statement refers to those statements which are used to repeat a set of statements
        for the specified number of times a until a certain condition is fulfilled. As soon as the condition becomes false,
        the loop terminates. These statements consist of three values:
         u A starting value(i.e. initializing the starting value of a variable)

         u A test expression
         u A step value(using increment or decrement operator)
        In Python, the two basic types of iterative statements are as follows:

         u for loop
         u while loop

        For Loop

        The For loop statement is used to repeat itself over a range of values or sequences when the number of iterations
        is known.

        In other words, this loop is used when you are sure about how many times a block of code will be executed. The
        For loop is also known as definite loop. The basic syntax of for loop is as follows:
              for<variable>in<sequence>:
                  Body of loop(Set of Statements)
              Or
              for<variable> in range( starting value, final value, step value)
                  Body of loop(Set of Statements)
        You should remember that the initialisation statement is executed only once.
        Program to print all the numbers defined in the sequence using for loop.
        Example:
















                                                                                                             119
                                                                                                             119
   248   249   250   251   252   253   254   255   256   257   258