Computer Science 1 while

Slides:



Advertisements
Similar presentations
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Advertisements

An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Pascal Programming Pascal Loops and Debugging. Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used.
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:
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Computer Science 1 How do you store a bunch of similar stuff?
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
AP Java Java’s version of Repeat until.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
GCSE COMPUTER SCIENCE Practical Programming using Python
Loops BIS1523 – Lecture 10.
Chapter 5: Control Structure
Review Dry Run A Little More Math Fix it Online time
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Program options Write a program for one of the following
Computer Science Dynamics.
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 2 Review the Bubble Sort
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
Computer Science Dynamics.
Repeat Day2 Dry Run Second Repeat Program
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
Computer Science 1 Warm-up: True/False Dry Run
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
What do you do when you don’t know how to get started.
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 make a guessing game?
Computer Science II Second With files.
Sorting Develop a sorting algorithm
Computer Science 2 More Trees.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Warm-up: Dry Run DIV / MOD 2nd If Then Program
How can you make a guessing game?
Computer Science
How do you store a bunch of similar stuff?
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
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
Random Numbers while loop
Dry Run Fix it Write a program
WJEC GCSE Computer Science
A bit of Review Review, Dry Run, Program.
Computer Science II First With files.
Presentation transcript:

Computer Science 1 while Warm up How do you…

Learning Objectives Understand the semantics and syntax of another looping structure. Be able to write a program using this structure.

Warm-up In Pascal, write a program that can be used to find the total of the test scores for students in this class.

How do you…(use pseudo-code) Modify this to work for a teacher in another class? Keep in mind how easily teachers make mistakes… not being able to count the number of students in class… Keep in mind how lazy teachers are… Not wanting to type in anything they don’t have to…

You need something that can… Get another score every time the teacher adds a score. Repeat an unknown number of times Be able to stop getting scores when the teacher types in a special score for quitting (flag or sentinel) Possibly 0 times. (No students in class)

While..do loop When to use it… When you need to repeat something an unknown number of times When it might not occur. Examples If you are getting a bunch of stuff from a person While the condition is true, it will go through the loop.

While..loop semantics Get Variable While (variable<>flag) do Begin {Commands you will repeat} End {Note: This will be on every test/quiz from now to the end of the semester!!}

While..loop Syntax While (condition) do Begin End; More than one command; End; Commands;

Dry Run program whiley; var a,b:integer; begin a:=0; b:=10; while (a<b) do a:= a + 4; writeln(a,b); end; writeln('Done'); end.

Use the following input: Dry run #2 Use the following input: 10, 8, 30, 6, 14, -1 program whilez; var score, x:integer; begin x:=0; writeln('Please enter a score, -1 to quit'); readln(score); while (score <> -1) do if score > x then x := score; end; writeln(‘Here is is ', x); end.

Check for Understanding: Dry run Program WhatDoesItPRintOut; var a:integer; begin a:=5; while (a>2) do case a of 1,2: a:=a-1; 3: a:=a*2; 4,5:a:=a-1; 6:a:=a-4; end; writeln(a); End.

So… Modify the code to get an unknown number of scores and returning the total.

While loop program options Input: An unknown number of scores Output: The total and average score. Push: Calculate the highest and the lowest score Input: An unknown number of names and ages. Output: The name and age of the oldest person. Write a program t' hold an election for t' worst pirate (Unknown # o' voters…) Black Beard T' Great Pirate Roberts Henry Morgan t' Terrible Show t' results o' t' vote and declare t' worst pirate.

While loop program 2 Millionaire Slug in Well Menu for projects Input: A starting amount of money and an interest rate. Output: A chart showing how much money the user has after each year and how many years it will take to become a millionaire. Push: Add a feature that incorporates an annual donation to savings Push: Modify it to compound monthly Slug in Well Input: The depth of a well. Process: The slug climbs up 3’ each day, but if it does not climb out of the well then it slides back down 2’ at night Output: A chart showing the height of the slug at the end of each day and the number of days it takes the slug to climb out of the well. Push: Show it graphically Menu for projects Create a menu using the while loop that will let the user run a program you have written previously and when finished it will ask if you would like to run it again or quit. Rock-paper-scissors,…