Upcoming SlideShare
×

# Introduction to basic programming repetition

• 4,466 views

Reviewer Repetition or looping

Reviewer Repetition or looping

More in: Technology , Education
• Comment goes here.
Are you sure you want to
Be the first to comment
Be the first to like this

Total Views
4,466
On Slideshare
0
From Embeds
0
Number of Embeds
0

Shares
84
0
Likes
0

No embeds

### Report content

No notes for slide

### Transcript

• 1. Introduction to BASIC Programming
RepetitionFlowchart
• 2. Structure
Sequence
Selection
Repetition
• 3. SEQUENCE
In a computer program or an algorithm, sequence involves simple steps which are to be executed one after the other.
• 4. Make a Flowchart to add two numbers and print the result.
START
S=0: n1=0: n2=0
n1, n2
S= n1+n2
Print S
STOP
• 5. DECISION structure
• 6. SELECTION
Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed
• 7. Example
Compute the sum of x and y if x is greater than y, other wise print d as their difference.
Draw a flowchart to find the largest of three numbers A, B, and C.
• 8. Repetition
• 9. Repetition
Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met.
An occurrence of repetition is usually known as a loop.
Thebody of the loop is executed repeatedly while the termination condition is true.
• 10. Repetition (Pre-Test Structure)
A pre-tested loop is so named because the condition has to be met atthe very beginning of the loop.
This construct is often called a guarded loop.
• 11. Repetition (Post-Test Structure)
• A post-tested loop executes the body of the loop before testing the termination condition.
• 12. This construct is often referred to as an unguarded loop.
• Variables (in memory):
Num [ 4 ]
Result [ ]
Count [ ]
Input:
Num <- 4
Enter a Number => 4
Count = 4
4 > 0 ? => YES
Count = 3
3 > 0 ? => YES
Count = 2
2 > 0 ? => YES
Count = 1
1 > 0 ? => YES
Count = 0
0 > 0 ? => NO
Example:
What is the output of the following flowchart when the input is Num= 4
Variables (in memory):
Num [ 4 ]
Result [ 0 ]
Count [ 4 ]
Variables (in memory):
Num [ 4 ]
Result [ 7 ] 4 + 3
Count [ 2 ] 3 - 1
Variables (in memory):
Num [ 4 ]
Result [ 9 ] 7 + 2
Count [ 1 ] 2 - 1
Variables (in memory):
Num [ ]
Result [ ]
Count [ ]
Variables (in memory):
Num [ 4 ]
Result [ 10] 9 + 1
Count [ 0 ] 1 - 1
Variables (in memory):
Num [ 4 ]
Result [ 4 ] 0 + 4
Count [ 3 ] 4 - 1
Count: 4
Count: 3
Count: 2
Count: 1
Count: 0
Result: 10
• 13. Assignment
• 14. Review for the Long Quiz #3
• 15. Selection (Structure)
Determine if the input age is qualified to vote or not. If qualified, display “Qualified to vote!” if not, display “Too young!”
Given a number, print the message “Positive”, “Negative” or “Neither”
• 16. 3. The V. Mapa High School is accepting freshmen who are not more than 15 years old. Given the students’ name and age, print “ACCEPTED” if it meets the ages Requirement otherwise print “Sorry”
• 17. 4. Due to your poor results in the examination, I decided to increase each one of you by 5 points. Input your grade and print the new grade. If the original grade exceeds 90, then it remains as is.