Page 203 - AI Ver 1.0 Class 10
P. 203

• If only two parameters are used then step value becomes 1 as default.
                    • If only one parameter is used the start becomes 0 and step becomes 1 as default.
                    • If Start > End then Step = -ve integer should be given.

                    • If Start < End then Step = +ve integer.
                    • If Start >= End and step value is not specified then it assumes as +ve which is an invalid condition to run a loop
                    so the loop will not execute at all. For examples:




























                               Brainy Fact

                      Comparison operators (<, >, <=, >=, =, ==) and Boolean Operators (and, or) returns True or False.






                 The While Loop
                 The while loop is used to repeat a set of instructions as long as the condition is True. It means when the number
                 of iterations is not fixed/indefinite before we start with the execution of a loop. It is therefore known as indefinite
                 loop. Indentation of statements is must to specify the block of statements to be repeated using while loop. This
                 loop is also called an entry-controlled loop as it checks for the condition in the beginning only. If the condition
                 is True then the body of the loop will be executed. If the condition is False then it will not be allowed to enter
                 within the loop and it stops.

                 Syntax for the while loop:
                     while <condition>

                        Statements
                 Where,
                     •  while  is a reserved keyword.


                     •   condition is the criteria to repeat the instructions. The instructions repeat till the condition is True. As
                        soon as the condition is False it exits from the loop.
                     •   Statements are always indented can be single or a block. They are repeated till the condition is True.





                                                                                           Advance Python   201
   198   199   200   201   202   203   204   205   206   207   208