Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 125 - 2609_Logicode
P. 125

    THE INFINITE LOOP
                     If the condition given in a loop never becomes false, then the loop will never terminate and run

                     indefinitely. This type of loop is called an infinite loop.
                     Example:
                     while(1):
                         print("Hello")
                     Output: Hello will be printed infinite times.
                     To come out of the infinite loop, we can either close the program window. This will break the

                     running of the program.

                          PURE       We should not  use assignment operator in place of equality comparison operator
                          FACT       in the test condition as it may cause an infinite loop.

                     THE WHILE LOOP USING ELSE STATEMENT

                     Python enables the use of else statement with the while loop. The else block is executed when the
                     condition given in the while statement becomes false.
                     Program: To demonstrate the use of while loop with else statement.

                     On running the above program, you will get the following output:

                                                                                           Looping Statements in Python  123

| 120 121 122 123 124 125 126 127 128 129 130 |