CS 100, Summer 2001 Monday, 7/2 Lecture 5 ----------------------------------------------------------------------- Announcements: + Pick up (graded) Assignment 1 + Exercise 4 due Tuesday (7/3) + Changes: + Assignment 2 due Friday (7/6) + PRELIM 1 on Monday (7/9): covers Savitch Ch.1-3 + reading: Savitch ?? ----------------------------------------------------------------------- - Assignment 1: scores/errors/etc. + average: 38 (out of 50) + note that most people in the class will receive A's and B's. + 5 people got the bonus point - good job! ----------------------------------------------------------------------- Practice predicting output (important for Prelim 1): - savitch self-test Ch. 2 {7, 9, 10, 12}, Ch. 3 {7-9, 11-13, 17, 19, 21, 27-29} ----------------------------------------------------------------------- Topics: + debugging + while loops + do-while loops ----------------------------------------------------------------------- ----------------------------------------------------------------------- Testing/Debugging + methods: 1. compile the code (computer feedback) 2. try different values to see if you can "break" it - alpha testing vs. beta testing 3. verbally describe the algorithm to a friend (highlight assumptions!) 4. simulate on paper by hand 5. CodeWarrior debugger (breakpoints, variable watching): more on this later in the course ----------------------------------------------------------------------- ----------------------------------------------------------------------- + while loop - Syntax: how to write the while loop while (condition) { // loop body } Visual diagram: Start | v /-> Check cond | T/ \F \-Do body exit + executes 0 or more times + sentinel values: "invalid" values to signal the end of input EXAMPLE: read in Space Invaders scores, output avg, min, max - see SpaceInvadersWhile.java ----------------------------------------------------------------------- Another form: + do-while loop - Syntax: how to write the while loop do { // loop body } while (condition); // note semicolon is required here! Visual diagram: Start | v /-> body | | | v | check cond | T/ \F \----/ exit + note: executes 1 or more times - see SpaceInvadersDo.java (compare to previous version) ----------------------------------------------------------------------- (this should have been be lecture notes from Thursday (6/28)!) infinite loops (bad) + how stop in code warrior? ^C + what about operating systems? (e.g. Windows) + infinite loops can be useful. But we'll mostly avoid them here. ----------------------------------------------------------------------- PICK UP Assignment 1 and Exercise 3 (graded) PICK UP Assignment 2 and Exercise 4 (handout)