Page 48 - 2501_KVS_C-8
P. 48

4                                      PYTHON









                 Your Aim

                  4.1 Concept of Loop/Iteration: “FOR”
                  4.2 Practice Problems on “FOR” Loop




                  4.1 CONCEPT OF LOOP/ITERATION: “FOR”

                  In the real world, there are numerous situations in which one has to do some work repeatedly
                  up to a specific number of times. For example, if a student wants to print natural numbers up
                  to 10 or to print his/her name 100 times or to print a Maths table of a given number up to N.

                  But,  to  get  the  solution  of  the  above  questions  in  python,  we  need  to  understand  the
                  concept of a Loop.
                  Loop: A loop can be defined as a cycle of execution of various statements again & again up
                  to a specific number of times. Let us take an example to comprehend the concept of loop.

                  Example: To print the natural numbers up to 10, one must have the following commands:

                  (a)  First take a variable named COUNT and assign it a value 1,
                  (b)  Then, print COUNT,

                  (c)  Increase the value of COUNT by 1,
                  (d)   Now, check the value of COUNT whether it is less than or equal to 10. If it is less than

                       or equal to 10, then execute the steps (b), (c) and (d) again till the value of COUNT
                       reaches 10.
                  To understand the above program more clearly, we can draw its flow chart which is given below:


























                46                         KVS DELHI REGION 2025
   43   44   45   46   47   48   49   50   51   52   53