Loop Pattern
Rule of Thumb. If you smell an iteration, write it down.
- Decide between definite iteration and indefinite iteration
- Write down an appropriate pattern for the iteration.
- Do not fill in the pattern yet.
-
/* Given A[0..N] sorted in non-decreasing order, return the subscript of an occurrence of val in A (if val occurs in A) or N+1 otherwise. */
int find(int[] A, int N, int val)
while ( _______________________)
return ___________________________;