Code Listing 4: Shifting from a FOR loop to a WHILE loop—and just one way out

 1  CREATE OR REPLACE FUNCTION matching_row (
 2     title_list_in IN title_collection_t,
 3     title_in IN VARCHAR2
 4     ) RETURN PLS_INTEGER
 5  IS
 6     l_row PLS_INTEGER;
 7     return_value PLS_INTEGER;
 8  BEGIN
 9     l_row := title_list_in.FIRST;
10
11     WHILE (l_row IS NOT NULL AND return_value IS NULL)
12     LOOP
13        IF title_in = title_list_in (l_row)
14        THEN
15           return_value := l_row
16        ELSE
17           l_row := title_list_in.NEXT (l_row);
18        END IF;
19     END LOOP;
20
21     RETURN return_value;
22* END matching_row;