Computer Science 1 For..do loop Dry Run Take notes on the For loop

Slides:



Advertisements
Similar presentations
E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Advertisements

Looping while … do …. Condition Process 2 Process 1 Y Repeated Loop.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
CS150 Introduction to Computer Science 1
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Programming, an introduction to Pascal
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
Java Review if Online Time For loop Quiz on Thursday.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 11.
Computer Science 1 How do you store a bunch of similar stuff?
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
15.1 More About High-Level Programming Languages Syntax and Semantics Each programming language contains its own rules for both syntax and semantics. Syntax.
Program Options: 10 Minutes online
Review Dry Run A Little More Math Fix it Online time
Program options Write a program for one of the following
Java Fix a program that has if Online time for Monday’s Program
Introduction to pseudocode
Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.
How do you store a bunch of similar stuff?
Computer Science II First With files.
Computer Science II First With files.
Truth tables: Ways to organize results of Boolean expressions.
How can you model playing rock-paper-scissors?
Review Dry Run Taking Names Online time Math is Good
Computer Science 2 Arrays of Records.
Computer Science 1 Get out your notebook
Continue on the Array of Records program
Computer Science 2 Arrays of Records.
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
Program Options: 10 Minutes online
Truth tables: Ways to organize results of Boolean expressions.
Java Fix a program that has if Online time for Monday’s Program
Repeat Day2 Dry Run Second Repeat Program
Computer Science 2 Arrays of Records.
Let’s all Repeat Together
How do you store a bunch of similar stuff?
Computer Science 1 Warm-up: True/False Dry Run
Computer Science
Computer Science 2 Tally Arrays 2/4/2016.
Truth tables: Ways to organize results of Boolean expressions.
AP Java 9/21/2018.
Computer Science 1 Online time for Graphics Program Random review
How can you model playing rock-paper-scissors?
How can you make a guessing game?
Computer Science II Second With files.
Computer Science Procedures Day 2.
Computer Science 2 More Trees.
Computer Science 1 while
How can you make a guessing game?
Computer Science
How do you store a bunch of similar stuff?
Computer Science
Computer Science I: Get out your notes.
Continue on the Valentines program
How can you model playing rock-paper-scissors?
Program options Write a program for one of the following
Computer Science 1 while
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Random Numbers while loop
Computer Science 1 while
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Dry Run Fix it Write a program
A bit of Review Review, Dry Run, Program.
COMPUTING.
Computer Science II First With files.
Presentation transcript:

Computer Science 1 For..do loop Dry Run Take notes on the For loop Complete one of the for loop programs.

Dry Run What is this program doing? How can you modify this to find the total of three scores the user entered? How would you modify it to find the total of four scores? Five scores? 100 scores?

Computer Science 1 For loop

Learning Objective Be able to implement a loop in a program

Constructs Linear, You do something, then the next thing, … Decision, Writeln, readln, :=, .. Decision, If..then If..then..else case Looping, You repeat something. For..do Repeat..until While..do

For..do loop When Semantics Syntax When you need to repeat something a set number of times Semantics Syntax For loopingvariable := start to finish do Begin Code that is repeated end Can be a constant ( 1 or 5 ) or a variable or an expression that results in a matching type Must be an ordinal type variable. (Integer/ char) No ; Use to for counting up and downto for counting down You can leave off the begin and end if there is only one line of code being repeated.

For loop total example How would you modify this to get 5 scores? //Mr. Smith // For loop example program // Computer Science 1 // 9 - 16 - 08 program fortotal; var score, total, count: integer; begin total:=0; for count:= 1 to 4 do writeln('Please enter a score.'); readln(score); total:= total + score; end; writeln('The total of the scores = ', total); end. How could you have the program echo the user’s input to the screen? How would you modify this to get 5 scores? How could you let the user determine how many times it will go through the loop?

Dry Run For count:= 2 to 5 do Begin End; If (count mod 2) = 1 then Writeln(‘Dino’) Else Writeln(‘Scooby’); End;

Program options Input 8 scores, find the average (Add the scores and divide by the number of scores.) Power: Input the base and the exponent. And calculate and show the power Ex. Input base = 2, exponent = 3 Calculation: 2^3 = 2*2*2 Displays 2^3 = 8 Factorial: Input a positive integer, output it’s factorial. Ex.: Input 5 Calc: 5! = 1*2*3*4*5 Output: 5! = 120