Page 2 - Lesson Note - Iterative Statement
P. 2

Lesson Note
               Jump statements
               break
               break statement terminates the execution of the loop (for/ while) and the execution
               resumes from the statement immediately following the body of the terminated statement.

               continue
               continue statement terminates the execution of a particular iteration of the loop (for/
               while) and the execution resumes from the next iteration.

                        i=1                                 i=1
                        while (i<10):                       while (i<10):
                           i = i+1                              i = i+1
                           if (i%4 == 0):                       if (i%4 == 0):
                               break                               continue
                           print(i, end='')                     print(i, end='')

                        Output                              Output
                        23                                  235679



               Loop else statement

               The else clause of a Python loop executes when the loop terminates normally, not when the
               loop is terminating because of break statement

                        i=1                                 i=1
                        while (i<10):                       while (i<10):
                           i = i+1                              i = i+1
                           if (i%4 == 0):                       if (i%4 == 0):
                               break                               continue
                           print(i, end='')                     print(i, end='')
                        else:                               else:
                           print("Loop over")                   print()
                                                                print("Loop over")
                        Output                              Output
                        23                                  235679
                                                            Loop over



               Random Number generation in Python

               Function randint() generates a random number.
               Syntax:  randint(lower limit, upper limit)
                        (returns a random number N such that lower_limit<=N<=upper_limit)

               Example:
               #generates a random number N, such that 10<=N<=50
               import random
               x = random.randint(10, 50)
               print(x)
   1   2   3   4