Page 90 - KEC Khaitan C8 Flipbook
P. 90

B1
                  ITERATION IN PYTHON                                                                    CHAPTER


















                     Learning Outcomes                                                                            95%


                     The student will be able to:
                        understand the concept and syntax of a for loop.
                        understand the concept and syntax of a while loop.
                         apply jump statements (such as break, continue, and return) to alter the normal flow of program
                       execution.




                  As you know, a computer program is a set of instructions given to the computer to perform
                  a specific task. These individual instructions are known as statements. All the statements are
                  executed  sequentially,  one  after  the  other,  as  they  appear  in  a  program.  However, in  some

                  situations,  we have to change the order of execution of the program based on certain conditions.
                  In such situations, we use control statements to control or change the flow of execution.



                            ITERATIVE STATEMENTS

                  Iterative statements refer to the statements that are used to repeat a task based on a given
                  condition. These statements are also known as looping statements. An iteration means one pass
                  of a loop.

                  Python provides the following iterative statements:

                  (i)  For loop                    (ii)  While loop


                  THE for LOOP
                  The for loop is a type of iterative statement that allows the user to repeat a set of statements
                  multiple times until a given condition is falsified. The for loop is commonly used when the number
                  of iterations is known in advance or when iterating over a sequence, such as a list, string, tuple,
                  or a range."

                  The syntax of for loop is as follows:
                  for <counter variable> in range(start, stop, step_size):
                      statements



                   88   Premium Edition-VIII
   85   86   87   88   89   90   91   92   93   94   95