Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7COSC 181 – Foundations of Computer ProgrammingClass 10Announcement1st TestFri. Feb 20thComprehensive through the end of MondayClosed Note/Closed BookRead and Interpret Code“trace” codeWrite Code SnippetsSmall programs or parts of programsSyntax matters!Multiple-Choicewhile Repetition StatementRepetition statementAction repeated while some condition remains truePseudocodeWhile there are more items on my shopping list Purchase next item and cross it off my list •while loop repeats until condition becomes falseExample•int product = 3;while ( product <= 100 ) product = 3 * product;•What will product equal when the loop stops executing?What does this example do?Example•int product = 3;while ( product <= 100 ) product = 3 - product;Try ItUse a single while statement to write the code for our last homework.Read in 20 charactersTell me how many a’s, e’s, i’s, o’s, and u’s there are.Common Error - #1Initialize each counter and total, either in its declaration or in an assignment statement. Totals are normally initialized to 0. Counters are normally initialized to 0 or 1, depending on how they are used (we will show examples of when to use 0 and when to use 1).Common Error - # 2Using a loop’s counter-control variable in a calculation after the loop often causes a common logic error called an off-by-one-error. In a counter-controlled loop that counts up by one each time through the loop, the loop terminates when the counter’s value is one higher than its last legitimate value (i.e., 11 in the case of counting from 1 to


View Full Document

UVa-Wise COSC 181 - Foundations of Computer Programming

Download Foundations of Computer Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Foundations of Computer Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Foundations of Computer Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?