Page 48 - tp_Modula_v2.0
P. 48

THE WHILE STATEMENT
                                                                                                  Start
                  The while statement  executes a set of

                  statements repeatedly,  until the logical
                  expression evaluates  to  true.  When the
                                                                                                  Test         False
                  condition becomes  false, the control
                                                                                               Expression
                  comes out of the loop. The syntax of while
                  statement is given below.
                                                                  Increment/Decrement
                                                                                                      True
                  Syntax:
                  while (test expression):                                                Body of while loop

                        Statements
                        Increment/Decrement expression



                                                                                                   End

                  Program 5: To demonstrate the use of a while loop.                      Flowchart of 'while' Loop

                      Program5.py
                   File  Edit  Format   Run   Options  Window    Help

                   # program to demonstrate the use of while loop

                   i = 0
                   a = input("Enter the string: ")
                   while i < len(a):
                       if a[i] == 'e' or a[i] == 's':
                           i += 1
                           continue

                       print('Current Letter', a[i])
                       i+= 1





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

                      Output

                   Enter the string: Orange
                   Current Letter O
                   Current Letter r
                   Current Letter a
                   Current Letter n
                   Current Letter g








                   46     Touchpad MODULAR (Version 2.0)
   43   44   45   46   47   48   49   50   51   52   53