| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Lesson 2-8: Repetition Structures   WHILE  vs  REPEAT   UNTIL

Page history last edited by Ms. R. Singh 11 years, 6 months ago

 ‘WHILE’ LOOP CONSTRUCT vs ‘REPEAT…UNTIL’ LOOP CONSTRUCT

 

 

 

COMPARISON OF ‘WHILE’ LOOP AND ‘REPEAT...UNTIL’ LOOP

 

 

 

 

SIMPLE EXAMPLES OF ‘WHILE’ vs ‘REPEAT...

 

 

 

Eg.) Write an algorithm to accept an unspecified amount of integers.Calculate and print the sum of the numbers entered.  The program should be terminated when the number 999 is entered.

 

 

Answer: ‘WHILE’ LOOP 

 

Start

      Print(‘Please enter a number’)

      Read(num)

      WHILE (num <> 999) DO

                 sum = sum + num

                 Print(‘Please enter a number’)

                 Read (num)

       ENDWHILE

       Print(‘The sum is: ‘, sum)

Stop

 

 

Answer: ‘REPEAT...UNTIL’ LOOP

 

Start

      Print(‘Please enter a number’)

      Read(num)

      REPEAT

               sum = sum + num

               Print(‘Please enter a number’)

               Read(num)

       UNTIL (num = 999)

       Print(‘The sum is: ‘, sum)

Stop

 

 

 

 

 

 

 

 

 

 

 

  

  

Comments (0)

You don't have permission to comment on this page.