loops/script.rst
changeset 457 68813d8d80fb
parent 452 0a39cb296fb2
parent 410 226b6e789da5
equal deleted inserted replaced
456:be96dc6c9743 457:68813d8d80fb
    30 Hello Friends. Welcome to the tutorial on loops in Python. 
    30 Hello Friends. Welcome to the tutorial on loops in Python. 
    31 
    31 
    32 {{{ Show the outline slide }}}
    32 {{{ Show the outline slide }}}
    33 
    33 
    34 In this tutorial, we shall look at ``while`` and ``for`` loops. We
    34 In this tutorial, we shall look at ``while`` and ``for`` loops. We
    35 shall then look at the ``break``, ``continue`` and ``pass`` keywords
    35 shall then look at how to break out of them, or skip some iterations
    36 and how to use them. 
    36 in loops.
    37 
    37 
    38 .. #[[Anoop: for loop is a pre-requisite and has been already covered,
    38 .. #[[Anoop: for loop is a pre-requisite and has been already covered,
    39    so i think our emphasize can be on while loops]]
    39    so i think our emphasize can be on while loops]]
    40 
    40 
    41 .. #[[Anoop: Instead of saying we will learn keywords pass, break and
    41 .. #[[punch: I think, we should have both of them. It gives a better
    42    continue, I think it is better to tell them that we will learn more
    42 .. context and comparison.]
    43    about loops]]
       
    44 
    43 
    45 {{{ switch to the ipython terminal }}}
    44 {{{ switch to the ipython terminal }}}
    46 
    45 
    47 We have an ``ipython`` terminal, that we shall use through out this
    46 We have an ``ipython`` terminal, that we shall use through out this
    48 tutorial. 
    47 tutorial. 
   143 iteration and continue to the end of this iteration. 
   142 iteration and continue to the end of this iteration. 
   144 
   143 
   145 .. #[[Anoop: should add slides for break, continue, pass]]
   144 .. #[[Anoop: should add slides for break, continue, pass]]
   146 
   145 
   147 Say, we wish to print the squares of all the odd numbers below 10,
   146 Say, we wish to print the squares of all the odd numbers below 10,
   148 which are not multiples of 3, we would modify the for loop as follows.
   147 which are not multiples of 3, we would modify the ``for`` loop as
   149 ::
   148 follows.  ::
   150 
   149 
   151   for n in range(1, 10, 2):
   150   for n in range(1, 10, 2):
   152       if n%3 == 0:
   151       if n%3 == 0:
   153           continue      
   152           continue      
   154       print n*n
   153       print n*n
   156 
   155 
   157 Following is an exercise that you must do. 
   156 Following is an exercise that you must do. 
   158 
   157 
   159 {{{ switch to next slide }}}
   158 {{{ switch to next slide }}}
   160 
   159 
   161 %%3%%Using the ``continue`` keyword modify the ``for`` loop to print
   160 %%3%%Using the ``continue`` keyword modify the ``for`` loop, with the
   162 the squares of even numbers below 10, to print the squares of only
   161 ``range(2, 10, 2)``, to print the squares of even numbers below 10, to
   163 multiples of 4. (Do not modify the range function call.) 
   162 print the squares of only multiples of 4.
   164 
       
   165 .. #[[Anoop: can you be more explicit/specific on do no modify say we
       
   166    can ask them to use range(2, 10, 2) and solve the problem]]
       
   167 
   163 
   168 Please, pause the video here. Do the exercise and then continue. 
   164 Please, pause the video here. Do the exercise and then continue. 
   169 
   165 
   170 {{{ switch to next slide after a seconds break}}}
   166 {{{ switch to next slide after a seconds break}}}
   171 
   167