Download presentation
Presentation is loading. Please wait.
Published byEthel Morrison Modified over 8 years ago
1
Loops When you want a computer to perform the same operation many times you use a loop. Looping is one of the keys to computer programming. First we will look at the FOR / DO Loop. Later in the semester we will look at some other loops provided by Pascal.
2
Loops (con’t) Reminder: A compound statement is a group of statements beginning with BEGIN and ending with END. BEGIN writeln (‘Who shot Mr. Burns?’); readln (answer); END;{Note: no period - only at the end of the program}
3
FOR-DO Loop FOR Index:= 1 to 100 DO writeln(‘Nobody likes sunburn slappers ‘); FOR Index:=1 to 10 DO BEGIN write(Index); writeln(‘Next time it could be me a the scaffolding’); END
4
Averaging numbers (example from book) Suppose you want to write a program that will average grades in general (ie. You may use a different number of grades each time you run the program.) –requirements specification –analysis –design –implementation / coding –testing
5
Requirements Specification Since the English description for this problem is so straightforward, the requirements specification step is trivial for this example.
6
Analysis Inputs: –# of grades to be averaged:integer –the grades to be averaged:integers Outputs: –the average:real other variables: –sum of the grades read so far
7
Design: First version of pseudocode Read the number of grades to be averaged; Sum all the grades to be averaged Compute and print the average
8
Design: Pseudocode refinement Read the number of grades to be averaged; Set Sum to zero FOR GradeNum:= 1 TO TotalGrades DO –BEGIN Read the Grade; Add the grade to Sum; –END; {FOR} –Compute the Average; –Print the sum and average;
9
Implementation
10
testing
11
Midterm #1 Chapters 2 (not really), 3, 4, and 5 October 19, 1999 (2 weeks from today) review on Thursday October 14, 1999 –old midterm on Web (Marateck’s page) –my review –your questions website to have my review materials within one week
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.