Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured Programming Constructs March, 2011Copyright 2011 - Yvette Francis.

Similar presentations


Presentation on theme: "Structured Programming Constructs March, 2011Copyright 2011 - Yvette Francis."— Presentation transcript:

1 Structured Programming Constructs March, 2011Copyright 2011 - Yvette Francis

2  Sequence  Selection  Repetition March, 2011Copyright 2011 - Yvette Francis

3  Places steps in correct logical order What’s wrong here? 1.Place letter in envelope 2.Drop letter in mailbox 3.Seal envelope 4.Fold letter to fit envelope 1.Fold letter to fit envelope 2.Place letter in envelope 3.Seal envelope 4.Drop letter in mailbox March, 2011Copyright 2011 - Yvette Francis

4  Expresses choice of action based on a condition Example:  Persons under 18 years are not allowed to vote  Only drivers 25 years and over receive a discount of 10% March, 2011Copyright 2011 - Yvette Francis

5  Allows one or more steps to be repeated based on a condition or for a specified number of times Example:  Each of the 5 numbers received must be doubled  Calculate the VAT inclusive price for each of 10 items March, 2011Copyright 2011 - Yvette Francis

6 IF condition THEN action ENDIF Example: If age < 18 then Print “Voting not allowed” Endif Example: If DriverAge >= 25 then Premium = Premium *.90 Endif March, 2011Copyright 2011 - Yvette Francis

7 IF condition THEN action1 ELSE action2 ENDIF Example: If age < 18 then Print “Voting not allowed” Else Print “You may vote” Endif Example: If DriverAge >= 25 then Premium = Premium *.90 Else Premium = Premium * 1.1 Endif March, 2011Copyright 2011 - Yvette Francis

8 FOR loop-index = start-value TO end-value DO statements…. ENDFOR Example: FOR rep = 1 TO 5 DO Read num num = num * 2 ENDFOR Example: VATRate =.15 FOR count = 1 TO 10 DO Read price FinalPrice = price + price * VATRate ENDFOR March, 2011Copyright 2011 - Yvette Francis

9 WHILE condition DO statements…. ENDWHILE Example: num = 1 WHILE num <= 12 DO answer = num * 2 num = num + 1 Print answer ENDWHILE Example: VATRate =.15 Read price WHILE price <> 0 DO FinalPrice = price + price * VATRate Read price ENDWHILE March, 2011Copyright 2011 - Yvette Francis

10 REPEAT statements…. UNTIL condition Example: num = 1 REPEAT answer = num * 2 num = num + 1 Print answer UNTIL num = 13 Example: VATRate =.15 Read price REPEAT FinalPrice = price + price * VATRate Read price UNTIL price = 0 March, 2011Copyright 2011 - Yvette Francis

11 REPEAT statements…. UNTIL condition test-after loop performed at least once WHILE condition DO statements…. ENDWHILE test-before loop may not be performed even once March, 2011Copyright 2011 - Yvette Francis

12 REPEAT Example: num = 1 REPEAT answer = num * 2 num = num + 1 Print answer UNTIL num = 13 Example: VATRate =.15 Read price REPEAT FinalPrice = price + price * VATRate Read price UNTIL price = 0 WHILE Example: num = 1 WHILE num <= 12 DO answer = num * 2 num = num + 1 Print answer ENDWHILE Example: VATRate =.15 Read price WHILE price <> 0 DO FinalPrice = price + price * VATRate Read price ENDWHILE March, 2011Copyright 2011 - Yvette Francis


Download ppt "Structured Programming Constructs March, 2011Copyright 2011 - Yvette Francis."

Similar presentations


Ads by Google