COSC 181 Foundations of Computer Programming Class 10 Announcement 1st Test Fri Feb 20th Comprehensive through the end of Monday Closed Note Closed Book Read and Interpret Code Write Code Snippets trace code Small programs or parts of programs Syntax matters Multiple Choice while 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 oneerror 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 10
View Full Document