Ads

Repetition or Iteration Structure

A third structure causes the certain steps to be repeated.


The Repetition structure can be implemented using,

• Repeat Until Loop
• The While Loop
• The For Loop

Any program instruction that repeats some statement or sequence of statements a number of times is called an iteration or a loop. The commands used to create iterations or loops are all based on logical tests. There three constructs for iterations or loops in our pseudocode.

The Repeat Until loop

The syntax is; 

REPEAT
A statement or block of statements
UNTIL a true condition

Example 1: A program segment repeatedly asks for entry of a number in the range 1 to 100 until a valid number is entered.

REPEAT
DISPLAY “Enter a number between 1 and 100”
ACCEPT number
UNTIL number < 1 OR number > 100

Example 2: A survey has been carried out to discover the most popular sport. The results will be typed into the computer for analysis. Write a program to accomplish this.

REPEAT
DISPLAY “Type in the letter chosen or Q to finish”
DISPLAY “A: Athletics”
DISPLAY “S: Swimming”
DISPLAY “F: Football”
DISPLAY “B: Badminton”
DISPLAY “Enter data”
ACCEPT letter
If letter = ‘A’ then
Athletics = athletics + 1
If letter = ‘S’ then
Swimming = Swimming + 1
If letter = ‘F’ then
Football = Football + 1
If letter = ‘B’ then
Badminton = Badminton + 1
UNTIL letter = ‘Q’
DISLAY “Athletics scored”, athletics, “votes” 
DISLAY “Swimming scored”, swimming, “votes”
DISLAY “Football scored”, football, “votes”
DISLAY “Badminton scored”, Badminton, “votes”


     


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

buttons=(Accept !) days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !