



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Lecture 22
Fall 2008
requires separate assignment statements for all 11 counters
requires a cascading if-else statement with 11 cases
not easily generalized – what if we wanted to use 8-sided dice?
the resulting code is shorter, simpler, and easier to generalize
function SeqSearch(list, desired) //// Assumes: listReturns: index is of an list array where desired of items first appears, // or -1 if not found { var index; index = 0; // START AT FIRST ITEM while (index < list.length ) { // AS LONG AS ITEMS LEFT if (list[index] = desired ) { // IF NEXT ITEM IS DESIRED ONE, return index; // THEN RETURN WHERE FOUND } index = index + 1; // GO ON TO NEXT ITEM } return -1; // IF FAILED TO FIND, RETURN - }
Any error?