Page 44 - tp_Modula_v2.0
P. 44

04             LOOPING STATEMENTS



                                                                                                IN PYTHON















                         Your Aim

                         to learn about:

                                   The for Statement                       The while Statement

                                    The jump Statements                       Some More Programs





                  Sometimes, you need to repeat a task multiple time or you may need to repeat the task either a
                  certain number of times or until a condition is satisfied. In Python, the statements that are used
                  to repeat a set of instructions are called iterative or looping statements. Looping statements are
                  very useful and necessary for developing applications.

                  Python provides two types of looping statements—for and while. The for statement is used
                  to repeat an instruction or a set of instructions a fixed number of times. Whereas, the while

                  statement is used to repeat a set of instructions until a condition evaluates to true. Let’s discuss
                  these constructs in brief.

                      THE FOR STATEMENT
                                                                                             Start
                  The  for statement executes a simple or
                  compound statement for a fixed number of
                                                                                          Initialisation
                  times. The syntax of the for statement is given
                  below:

                  for <variable> in <iterator>:                                   False   Conditional
                         Statements                                                       Expression



                                                                                                 True
                                                                                       Body of for loop



                                                                              Stop
                                                                                     Flowchart of the 'for' Loop


                   42     Touchpad MODULAR (Version 2.0)
   39   40   41   42   43   44   45   46   47   48   49