Page 228 - Computer Science Class 11 Without Functions
P. 228

C T  04     What will be the output produced on the execution of the following code snippet?
                         for letter in 'world':
                             if letter == 'l':
                                 pass
                                 print(letter, end ='')
                             print(letter, end='')







             Let's Summarise


          Ø   The repeated execution of statements in a program is called iteration or looping.
          Ø   Python provides for and while statements to run a piece of code that can be run over and over again.
          Ø    The statement or a sequence of statements being executed in a loop is called the loop's body.
          Ø   range(start, stop, step) returns a sequence of integers beginning with start and going up to stop,
              but stepping over in chunks of size step.
          Ø   Syntax of for statement

              for control_variable in values in range / sequence:
                                   body of for loop

              [else:
                   statements]
              ❍  A sequence may be a values in range, list, string, tuple, or a dictionary.

              ❍  Control variable is a variable that takes the values in the sequence one by one.
              ❍  else block is executed after all the iterations of the for loop are executed.
          Ø   Syntax of while statement:
              while test condition:
                Body of while loop

              [else:
                Statements]

              ❍  test condition is the expression that will evaluate to either True or False
              ❍   body of while  loop constitutes the statement(s) that will be executed if the test condition is True.
                 These are determined through indentation. The first un-indented line marks the end of the loop.

              ❍  else (optional) is a keyword and the statements in else block (optional) will be executed after all the
                 possible iterations of the while loop are executed.
          Ø   A while loop becomes an infinite loop if the test condition never yields False.
          Ø   A pass statement is ignored by the Python interpreter.












         226   Touchpad Computer Science-XI
   223   224   225   226   227   228   229   230   231   232   233