Page 102 - Computer Genius Class 06
P. 102

Different Types of Loops

                  Loop runs a statement or group of statements multiple times till the given condition is true. There
                  are different types loops.  lthough they per orm the same tas    ut their  or ing is different.  et us
                  take a look at the types of loop.
                  Different types of loops are:

                  1.  hile  oop          2. For  oop           .  ested  oop

                  While Loop/Conditional Loop
                  While Loop executes a statement or group of statements till a given condition is true. Once the
                  condition is false, the loop is terminated.
                  Example: To print number from 1 to 10.
                  Condition: Write numbers from 1 to 10.
                  Decision: Have we reached number 0.
                  Pseudocode:

                  Program Start
                  set a to 0
                  while a is less than 10

                         increase the value of a by 1
                         display a
                  Program End
                  Example: To print a statement fi e times  y using a  hile loop.
                  Condition: Till the time the test expression remains true, the body of the while loop will run.
                  Decision:  a e  e printed the statement fi e times or not
                  Pseudocode:
                  Program Start
                  set a to 0
                  while a is less than 5
                      increase the value of a by 1
                      display Hello World
                  Program End

                  Example: To print number from 5 to 1.
                  Condition:  Till the time the test expression  remains  true, the body of  the while loop printing
                  statement will run and once the condition is false the loop will stop executing.
                  Decision: Have we printed 1?
                  Pseudocode:
                  Program Start
                  set a to 0
                  while a is equal to 1
                      display the value of a
                      decrease the value of a by 1
                  Program End


                      100    Computer Genius-VI
   97   98   99   100   101   102   103   104   105   106   107